PowerCLI

 View Only
  • 1.  Invoke-VMScript write-progress not outputting

    Posted May 03, 2016 08:22 AM

    Hi All,

    For the past few weeks I'm building a deployment script based on Excel-input.

    Basiclly to process goes like this;

    - you fill in an excel-file with all kind of resources like CPU, MEM, Diskspace but also if you like to install IIS or SQL.

    - When starting the script, the system reads all the cells of that excel-sheet and fills in variable that PowerCLI will be using.

    - PowerCLi is then creating the VM, based on your input.

    - After VM is created, there is only 1 file that will gets executing by invoke-vmscript.

    That line looks like;

    Invoke-VMScript -vm $VMName -ScriptText "Powershell.exe -ExecutionPolicy Bypass -File c:\PSScripts\StartConfiguration.ps1" -GuestUser administrator -GuestPassword *******

    That is a powershell script that will loop through a folder with all kind of PS-scripts. I have to do this so I have a modular deployment-script.

    Those PS-scripts on the local VM have write-progress and write-output, but I don't see them in my main-console. The one where I started all of this....

    When I launch them on my vm itself, I do see the progress-bar and the output.

    How do I get this working that I see the progress within my main-screen?

    By the way, I also tried executing one file (with progress-bar...) with invoke-vmscript but also that doens't work

    My invoke-vmscript looks like;

    Invoke-VMScript -vm $VMName -ScriptText "Powershell.exe -ExecutionPolicy Bypass -File c:\PSScripts\001-WAN-LAN_networkconfig.ps1" -GuestUser administrator -GuestPassword *******

    Hope someone knows.

    best regards

    Dave



  • 2.  RE: Invoke-VMScript write-progress not outputting
    Best Answer

    Posted May 03, 2016 08:33 AM

    The Invoke-VMScript cmdlet uses the GuestOperationsManager methods to run a command on or copy files to/from the guest OS.

    For that it uses the VMware Tools interface.

    In short when you use Invoke-VMscript to run a PowerShell script inside a guest, what happens in the background is the following:

    • copy the script/command to the guest OS
    • run the script/command from copied file
    • capture the resulting output in a file
    • copy the file with the output back to the caller of Invoke-VMScript

    The Write-Progress output is in a stream that is not captured by the above process, hence you don't get that output on the calling side.

    On a sidenote, the Invoke-VMScript is not an interactive type of session.

    If you want to see progress on the calling station, you will need to go to PowerShell Remote Sessions.