I'm looking to automate the use of Psexec through a Powershell script. The aim is to send mass commands to a list of servers. So far, nothing extraordinary when you know the possibilities of Psexec. The problem arises when I want to put the command to be executed on the remote machines in a variable. As soon as the command has a space, it cannot be executed on the remote machine and I get the error : The specified path cannot be found. I've tried putting my variable between "" or '' or `` but nothing changes.
In the script, this command works fine :
PsExec.exe \\$SelectedServerIP -u my_user -p my_password ipconfig /all
but these one don't work :
$command = "ipconfig /all"
PsExec.exe \\$SelectedServerIP -u my_user -p my_password $command
$command = "ipconfig /all"
PsExec.exe \\$SelectedServerIP -u my_user -p my_password ""$command""
$command = ipconfig /all
PsExec.exe \\$SelectedServerIP -u my_user -p my_password ""$command""
$command = ipconfig /all
PsExec.exe \\$SelectedServerIP -u my_user -p my_password """$command"""
Thank you for your answers.
LG