Forum Discussion
John_Dodo
Oct 17, 2022Brass Contributor
Replace psexec with native powershell commands
Hello, we have a remotely located ($remoteserver1) script that we want to run on the said remote computer ($remoteserver1) from a "controler" server (via a scheduled task). As of today in a C...
John_Dodo
Oct 17, 2022Brass Contributor
I think I found the solution myself. I simply had to replace the " " by { } in the $command var.
Though I still have an issue of the nested variables not beeing interpreted.
$command = {C:\_Scripts\Pools_Scripts\myscript.ps1" "param1" "$param2" "param3" "param4" }
Invoke-Command -ComputerName $remoteserver1 -ScriptBlock $command
For my test I wrote $param2 value and it's working. If I leave $param2 in $command it is not interpreted.
Though I still have an issue of the nested variables not beeing interpreted.
$command = {C:\_Scripts\Pools_Scripts\myscript.ps1" "param1" "$param2" "param3" "param4" }
Invoke-Command -ComputerName $remoteserver1 -ScriptBlock $command
For my test I wrote $param2 value and it's working. If I leave $param2 in $command it is not interpreted.
John_Dodo
Oct 17, 2022Brass Contributor
So apparently I must use $using:param2
$command = {C:\_Scripts\Pools_Scripts\myscript.ps1" "param1" "$using:param2" "param3" "param4" }
Invoke-Command -ComputerName $remoteserver1 -ScriptBlock $command
It seemd to work now.
If anyone can validate this 🙂
thank you
$command = {C:\_Scripts\Pools_Scripts\myscript.ps1" "param1" "$using:param2" "param3" "param4" }
Invoke-Command -ComputerName $remoteserver1 -ScriptBlock $command
It seemd to work now.
If anyone can validate this 🙂
thank you