Forum Discussion
Replace psexec with native powershell commands
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.
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 26, 2022Brass Contributor
Hi Lain,
I would get the expected output form the write-host yes. Not sure what you try to demonstrate though. 🙂
- 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
- 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.