Reputation: 165
Below is my striped down code. How can I determine what the current server is when parsing to Write-Host? With other words, what can I use instead of "$CURRENTSERVER"?
$servers = SERVER1,SERVER2,SERVER3
Try
{
Invoke-Command -ComputerName $servers -ErrorAction Stop -ScriptBlock{CODE}
}
Catch
{
Write-Host -ForegroundColor Yellow "[WARNING] Cannot connect to $CURRENTSERVER"
}
The information is there somewhere, if I run the command without try-catch I get
[SERVER3] Connecting to remote server SERVER3 failed with the following error message : WinRM cannot process the request.
Upvotes: 0
Views: 405