VMware Cloud Community
gcollp
Contributor
Contributor

How do i finish powershell.exe after execute a powershell script (.ps1)?

Hello!
I have a powershell script and i am executing it in a perl program, but i have a problem,  the process (powershell.exe) never finished after executed the .ps1
I need know how do i finish powershell.exe after exetute the .ps1 script.
I try to search any command for perl that force to close after end the work, but exit dont work. Please somebody can help me !!!
Thanks so much for your help!
Tags (3)
0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership

You can use the "exit" command as the last line of your PowerShell script. This will exit your PowerShell session.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership

You didn't say how you called the PowerShell script from Perl, but I suspect you called the powershell.exe binary.

Did you do anything like this ?

powershell.exe -File "C:\Scripts\myscript.ps1"

That should return when the script has finished (no reason to add an exit, that is there implictely at the end of the script).

You might try to add the NonInteractive parameter, but there should be no reason for that

powershell.exe -NonInteractive -File "C:\Scripts\myscript.ps1" 

You can do

powershell.exe -help

to see the other available parameters


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos