I rewrote some of your script. Check this out:
# Define the name of the service to stop/start
$ServiceName = 'wuauserv';
# Get a list of server names from a text file
$ServerList = Get-Content -Path 'C:\Servers.txt';
foreach ($Server in $ServerList){
# Stop service and wait
Get-Service -ComputerName $Server -Name $ServiceName | Stop-Service;
# Logic to see string. Looking for "ServerPort=%". Detect if Server port is 444 or 443. If one, set to other
# Read the config.ini file into $ConfigFile variable
$ConfigFilePath = "\\$Server\c$\config.ini";
$ConfigFile = Get-Content -Path $ConfigFilePath -Raw;
if ($ConfigFile -match 'ServerPort=443')
{
# Change ServerPort to 444
Set-Content -Path $ConfigFilePath -Value ($ConfigFile -replace 'ServerPort=443', 'ServerPort=444');
}
elseif ($ConfigFile -match 'ServerPort=444') {
# Change ServerPort to 443
Set-Content -Path $ConfigFilePath -Value ($ConfigFile -replace 'ServerPort=444', 'ServerPort=443');
}
else {
Write-Host -Object ('Could not find matching ServerPort value in {0}' -f $ConfigFilePath);
}
Get-Service -ComputerName $server -Name $ServiceName | Start-Service;
}