I am running following command remotely from PowerShell in Admin mode. This gets the status of App Pool (in IIS) from remote machine.
$result = Invoke-Command -ComputerName $servername -ScriptBlock {
param($appPoolName)
Get-WebAppPoolState -Name $appPoolName
} -ArgumentList $appPoolName | select value
If I am passing correct values I am getting proper data in $result but if I am passing invalid server name, I am getting below error.
"Connecting to remote server failed with the following error message : WinRM cannot process the request."
The issue is I am not getting anything in $result and even this is not going to Catch block. There is no way to identify if the command run successfully or not.
Please provide any pointers on how to get the command output in $result.
Note: I am the admin on remote machine and WinRM has been enabled.