I have a script that I need to run on the server from the client, which I do using Invoke-Expression to execute a WMIC command. em> and create a process " cmd / c ".
On the server I have the script and one of its parameters receives a string that must comply with this format:
-exclude "val1, val2, val3, val4"
But I have trouble passing it because it does not recognize me as valid the parameter.
When I build the command to execute, it looks like this:
WMIC /node:servername /user:remoteusername /password:remotepassword process call create CommandLine = "cmd /c powershell C:\folder\script.ps1 -Path C:\folder -Exclude val1, val2, val3, val4 -Selfdestruction" CurrentDirectory = "C:\"
Since the values of the -Exclude parameter are separated by commas, it takes them as if each one was a different parameter and is not executed correctly.
Neither can I pass the parameter in quotes, as would be done from PowerShell because Invoke-Expression does not recognize it as valid.