I am trying to run a command from the command line which I derived from a variable and it is not working. If I copy the output of the variable and run it from the command line it works, just not from within Powershell script
$psexec = "c:\sysinternalsSuite\psexec.exe"
$computer = "localhost"
$port = 5482
$urlacl_cmd = "$psexec \\$computer netsh http add urlacl url=http://+:$port/ user=everyone"
# tried both of the lines below; neither worked
invoke-command -scriptblock{$urlacl_cmd}
& $urlacl_cmd
output from the above results in this:
`
c:\sysinternalsSuite\psexec.exe \\localhost netsh http add urlacl url=http://+:5484/ user=everyone
& : The term 'c:\sysinternalsSuite\psexec.exe \\localhost netsh http add urlacl url=http://+:5484/ user=everyone' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Temp\add-websocket.ps1:11 char:3
+ & $urlacl_cmd
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (c:\sysinternals.../ user=everyone:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
`
If I just copy the output and past it in the Powershell prompt it works
c:\sysinternalsSuite\psexec.exe \\localhost netsh http add urlacl url=http://+:5484/ user=everyone