Product: PowerShell Universal
Version: 5.6.2
We have set up an Eventhub and we are trying to follow the examples on Event Hubs | PowerShell Universal.
The below works, and we can start Notepad on the remote computer:
Invoke-PSUCommand -Hub “MyHub” -Command “Start-Process” -Parameters @{
FilePath = “Notepad”
}
When we’re trying to follow the instructions under “Example: Running Scripts on Remote Machines”, we get our script over to the remote computer, but the execution does not happen, ie
“& $TempFile @Parameters” does not kick off the script.
Any suggestions on how to troubleshoot?
After some googling, I have found a way forward.
- Create a scriptblock, for example:
$testscript = {
Get-service | where Name -EQ “WinDefend” | Out-File "C:\ProgramData\PowerShellUniversal\helloworld.txt”
}
- Invoke that scriptblock with Invoke-PSUCommand and the command Invoke-Expression:
Invoke-PSUCommand -Command ‘Invoke-Expression’ -Hub myEventHub -Parameters @{
Command = $testscript
}
Now when trying to return information from the remote computer (the one where the PSU Agent is running), the following works when both computers are in the same domain and same VLAN:
$testscript = {
hostname
}
$Connection = Get-PSUEventHubConnection | Where-Object UserName -eq ‘Admin’ | Where-Object Disconnected -EQ $null | Select-Object -First 1
$Result = Invoke-PSUCommand -Command ‘Invoke-Expression’ -Hub myEventHub-ConnectionId $Connection.ConnectionId -Parameters @{
Command = $testscript
}
This returns the remote computer’s hostname as expected in the variable $Result.
However, when the remote computer is in another domain and another VLAN, we get this:
Invoke-PSUCommand : Status(StatusCode=“Unknown”, Detail="Exception was thrown by handler. HubException: Error trying to deserialize result to String. The JSON value could not be converted to
System.String
We have tried creating a $cred object with the credentials of an account with local admin rights on the server and running this:
$Result = Invoke-PSUCommand -Command ‘Invoke-Expression’ -Hub MGMTServers -ConnectionId $Connection.ConnectionId -Credential $cred -Parameters @{
Command = $testscript3
}
Unfortunately we still get the same error. Anyone that can point us in the right direction?
EDIT and extra information:
Only connectivity between two servers (PSU and agent) is TCP443