Hey all,
I’m usually lurking in the background learning from other folks issues, but for once I have to come out of the shadows and ask for some assistance. I’m working on a script that needs to run a particular executable on remote servers with a lot of switches. The executable isn’t always in the same location due to various factors outside of my control, but I’m finding it’s location through WMI based on where a running service points to, then splitting the string and removing the exe and replacing it with the other one in the same location I’m interested in. So far so good, but then comes the point I need to run that exe using invoke-command and I’m having some issues when I tried to pass the path through a variable instead of hard-coding it. I haven’t had a lot of need for invoke-command before, so I did what most people (should) do and I went digging through older posts in various powershell forums looking for answers, and looking for examples and tutorials. I learned a little that helped, but what they seem to indicate should work doesn’t seem to for me.
Since I was having issues with what I was doing, I decided to dumb this down to a local exe and play around to figure things out. So to start simple I pointed to c:\scripts\showmbrs.exe on my local machine.
Icm -computername mymachinename -scriptsblock { & “c:\scripts\showmbrs.exe”}
This seems to work getting a response from the exe, but remember the real exe I’ll be working with has a variable location so next I tried to pass it via a variable like I would in the actual script.
$test = “c:\scripts\showmbrs.exe”
icm -computername mymachinename -scriptsblock { & $test}
This gives me an error that after & the pipeline element produced an object that was not valid. Since $test should be a replacement string, this doesn’t make sense to me. I’ve hunted for a couple of days, finding various posts that seem to work the same way I’m doing it. If anyone can show me what I’m missing here, I’d appreciate the help.
For reference if you have additional input, where I will go from here is with an argument list holding multiple arguments to include other variables (hoping that will work but not there yet). My intended code looks something like:
$myargs = “-rAatuvqe -N $targethost -m $regManager -u $regID -p $regPass”
icm -computername mymachinename -scriptsblock { & $test} -argumentlist $myargs
Any insights will be appreciated.