0

Is there a script to input to exit VMware vSphere PowerCLI command prompt after executing a set of script for example created of VM.

MY last line of my .ps1 script is shown below, but the exit does not work, after executing my script, the command prompt is still there, unlike windows command prompt as the exit command works but not in powercli.

New-VM -name $vm  -DiskMB 10000 -memoryMB 4000
New-CDDrive -VM $vm -ISOPath  $win7 -StartConnected:$true -Confirm:$false
$scsiController = Get-HardDisk -VM $vm | Select -First 1 | Get-ScsiController
Set-ScsiController -ScsiController $scsiController -Type VirtualLsiLogicSAS -Confirm:$false

Start-VM -vm $vm
Exit
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
dwyane
  • 127
  • 2
  • 4
  • 8

1 Answers1

1

My hunch is that this has more to do with powershell and little to do with PowerCLI. I'm also guessing that the window closes if you focus it and press 'Enter'. I ran into this when executing some powershell scripts long ago, but never came across a decent fix until this evening. It seems powershell waits on a Readline() call after executing the script.

The solution: include the flag -InputFormat None in your call to powershell.exe. In your case, I'd include it in the call to the PowerCLI executable, it ought to be passed through.

Resources: This looks like a known issue from Microsoft's tracker. These two questions reference the same fix:

Please let me know if this works correctly, I'm not on a system with PowerCLI installed currently.

Good luck!

Community
  • 1
  • 1
Evan Powell
  • 960
  • 5
  • 4
  • Hi, How do I include the InputFormat None script in my current scipt? After running my script (test.ps1) the command prompt still remains. I just want to automatically close the command prompt. – dwyane Jul 29 '11 at 01:34
  • The -InputFormat None call goes on the call to execute powershell. For instance, if test.ps1 is my script I would call `powershell.exe -InputFormat None test.ps1` rather than `powershell.exe test.ps1`. – Evan Powell Aug 08 '11 at 15:23
  • Is the STDIN redirection bug relevant? No [redirection](http://technet.microsoft.com/en-us/library/bb490982.aspx) in the question, right? – noam Apr 10 '13 at 14:14