I'm currently facing a challenge while using remote PowerShell over SSH to execute a script on a Windows machine and pass parameters.
Locally, I run the script with parameters using this command:
.\Update-PasswordArchive.ps1 -LocalUserName Administrator
However, when attempting to run the script remotely using Invoke-Command, I encounter difficulties passing the -LocalUserName
parameter. Here's the remote command I use: *
Invoke-Command -HostName '192.168.1.100:54823' -FilePath C:\_scripts\Update-PasswordArchive.ps1
The problem is because, with Invoke-Command, I can't directly pass parameters for the script as I normally would. If I append the parameters after the script, it produces an error, as they are interpreted by the Invoke-Command itself rather than being passed to the script.
Is there a recommended solution or workaround for passing parameters when using Invoke-Command over SSH?
*(Don't get confused by the hostname, this is the IP of a VyOS Gateway and by the rule configured to port 54823 it useses NAT to forward to the desired maschine behind it) - So I assume there is no other way to remote PowerShell as SSH. I need a fix port and I have to use the IP:Port combination for the connection.