Automation

 View Only
  • 1.  Invoke-VMScript ScriptText Maximum Length

    Posted Feb 02, 2012 04:35 AM

    I'm trying to use Invoke-VMScript with some custom PowerShell scripts. It has been working fine, but I suddenly started getting no ScriptOutput and an ExitCode of 1. I believe this is due to an undocumented maximum length allowed for the ScriptText. My testing shows this to be 2869 characters. Notice the following commands and output. Notice that I am first loading the script using Get-Content into a string variable and restoring the newline characters. The expected output of this sample script is a write-host "GetUsersInDomain"

    ##################Loading a script with 2869 characters######################
    
    > $newscript = [string]::join([environment]::newline, (Get-Content C:\Users\Username\Desktop\GetUsers.ps1))
    > $newscript.Length
    2869
    > Invoke-VMScript -ScriptText $newscript -GuestUser "MYDOMAIN\username" -GuestPassword (Get-Credential).Password -VM DC1
    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Credential
    ScriptOutput
    -----------------------------------------------------------------------------------------------------------------------
    GetUsersInDomain
    |
    -----------------------------------------------------------------------------------------------------------------------
    
    #########After adding one more character in a comment section###################
    
    > $newscript = [string]::join([environment]::newline, (Get-Content C:\Users\Username\Desktop\GetUsers.ps1))
    > $newscript.Length
    2870
    > Invoke-VMScript -ScriptText $newscript -GuestUser "MYDOMAIN\username" -GuestPassword (Get-Credential).Password -VM DC1
    cmdlet Get-Credential at command pipeline position 1
    Supply values for the following parameters:
    Credential
    ScriptOutput
    -----------------------------------------------------------------------------------------------------------------------
    -----------------------------------------------------------------------------------------------------------------------
    

    Notice that the ScriptOutput of the second script is empty. If I assign the output to a variable, ExitCode=1 and Length=0. Can anyone confirm that this is a limitation of Invoke-VMScript? Any suggestions for a workaround. I know that -ScriptText can accept a file path (on the VM), but my goal is to have a single script that is run through VMware (i.e. no network access to VM), so I don't want to have to copy the file to each guest VM in order to run it. I suppose I could Copy-VMGuestFile first, then make the script self-deleting. I'm hoping for something more elegant/reliable



  • 2.  RE: Invoke-VMScript ScriptText Maximum Length

    Posted Feb 02, 2012 06:38 AM

    I can confirm this behaviour.

    My max number is a bit higher, but I see the same problem.

    Not sure if this is a PowerCLI or a Vix problem.