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...
LainRobertson
Oct 17, 2022Silver Contributor
Out of curiosity, in line 2 from the controller's script, you assign a value to a variable named $var, but on line 3, you use a variable named $vm in the -Argumentlist.
Maybe this is valid (since we can't see all the code - which is fine), but if it's a mistake, then maybe that explains the pausing after 2a is written. That said, I'm really guessing here since I don't know how Shutdown-VMGuest behaves if you pass a bad value (including $null) for the -VM parameter since I don't use VMware (I'm a Hyper-V guy.)
Cheers,
Lain
John_Dodo
Oct 17, 2022Brass Contributor
Oh I'm so sorry, it's an error when I wrote it. I fixed $var to $vm
It's not the exact code only the important part of it. So the value passed is right and I can actually see it in the first informational outputs just before this vmware command is ran.
I don't think it's specificaly related to beeing from vmware. I think it's more because this command does something particular. I don't know exactly how "far" I can go when using invoke-command, is there any limitations ?
Again, when I call the exact same script using psexec + parameters instead of invoke-command + parameters, both calls work but the second one get's stuck while the first one ends properly.
PS : Maybe I should say that the command returns this when running locally, it's normally not blocking as I don't use these parameters :
"WARNING: GuestId property is deprecated. Please use ConfiguredGuestId and RuntimeGuestId properties"
instead.
- LainRobertsonOct 17, 2022Silver Contributor
I can't see anything wrong when looking at it from a PowerShell perspective.
If you comment out the call to Shutdown-VMGuest from your vmware.ps1 script and run it again, do you then see the 2b and 3 output?
As an aside, you should really have a "break;" statement after the Write-Host "3" in between the current lines 11 and 12, or else you'll possibly fall through that case block and into the next one (if there is one, that is.)
write-host "3"; break; }
This isn't going to help with your current issue, just figured I'd flag it to avoid future potential issues.
Cheers,
Lain
- John_DodoOct 17, 2022Brass Contributor
If I comment the line with the call to shutdown-vmguest it works all fine until the end of the script.
- LainRobertsonOct 17, 2022Silver Contributor
Do you get anything printed out if you insert the following line before the actual Shutdown-VMGuest command in vmware.ps1?
Write-Host "Shutdown-VMGuest -VM $vmname -Confirm:`$false";
So, it'd look like this:
write-host "2a"; Write-Host "Shutdown-VMGuest -VM $vmname -Confirm:`$false"; Shutdown-VMGuest -VM $vmname -Confirm:$false;
Cheers,
Lain