Automation

 View Only
Expand all | Collapse all

Invoke Script Output Issues

  • 1.  Invoke Script Output Issues

    Posted May 31, 2018 02:03 AM

    Hi All,

    I'm hoping someone can help, I am trying to get outputs from a Invoke-VMScript to be used as inputs further on. Whilst the script works and gives the outputs I'm having issues in formating them to be used as inputs.

    The script is just a basic get-disk but i would like to be able to pipe the Number and OperationalStatus into a bigger Invoke-VMScript.

    Any help would be appreciated.

    $disks =  Invoke-VMScript -VM BNESTGFS001 -ScriptText 'get-disk' -ScriptType PowerShell

    ($disks).scriptoutput

    Number F Serial Number                    HealthStatus         OperationalStatu

           r                                                       s

           i

           e

           n

           d

           l

           y

           N

           a

           m

           e

    ------ - -------------                    ------------         ----------------

    0      V                                  Healthy              Online

    1      V                                  Healthy              Offline

    2      V                                  Healthy              Offline

    3      V                                  Healthy              Offline

    4      V                                  Healthy              Offline



  • 2.  RE: Invoke Script Output Issues

    Posted May 31, 2018 07:03 AM

    Try something like this

    $vmName = 'MyVM'

    $pattern = '(?m)^(?<devnumber>(?:[0-9]+)+)[\w\s]+?(?<status>(?:\w+)+)\s+\d+[\w\s]+$'


    $result = Invoke-VMScript -VM $vmName -ScriptText 'Get-Disk' -ScriptType Powershell

    $result.ScriptOutput.Split("`r") | Select-String -Pattern $pattern |

    Select @{N='Number';E={$_.Matches[0].Groups['devnumber'].Value}},

      @{N='Status';E={$_.Matches[0].Groups['status'].Value}}



  • 3.  RE: Invoke Script Output Issues

    Posted May 31, 2018 07:28 AM

    Thnx, not sure how to read the output.

    PS C:\WINDOWS\system32> $disks =  Invoke-VMScript -VM "VM" -ScriptText 'get-disk' -ScriptType PowerShell

    PS C:\WINDOWS\system32> $pattern = '(?m)^(?<devnumber>(?:[0-9]+)+)[\w\s]+?(?<status>(?:\w+)+)\s+\d+[\w\s]+$'

    PS C:\WINDOWS\system32> $pattern

    (?m)^(?<devnumber>(?:[0-9]+)+)[\w\s]+?(?<status>(?:\w+)+)\s+\d+[\w\s]+$

    PS C:\WINDOWS\system32> $disks.ScriptOutput.Split("`r") | Select-String -Pattern $pattern | Select @{N='Number';E={$_.Matches[0].Groups['devnumber'].Value}}, @{N='Status';E={$_.Matches[0].Groups['status'].Value}}

    PS C:\WINDOWS\system32> $stuff = $disks.ScriptOutput.Split("`r") | Select-String -Pattern $pattern | Select @{N='Number';E={$_.Matches[0].Groups['devnumber'].Value}}, @{N='Status';E={$_.Matches[0].Groups['status'].Value}}

    PS C:\WINDOWS\system32> $stuff

    PS C:\WINDOWS\system32>



  • 4.  RE: Invoke Script Output Issues

    Posted May 31, 2018 08:25 AM

    What is the exact output of the Invoke-VMScript cmdlet (the ScriptOutput part).
    Is that what you showed in the beginning of this thread?

    For me it seems to work



  • 5.  RE: Invoke Script Output Issues

    Posted May 31, 2018 08:41 AM

    yep, that's all i get.

    Pic



  • 6.  RE: Invoke Script Output Issues

    Posted May 31, 2018 08:45 AM

    Can you eventually attach the ScriptOutput content in a .txt file?



  • 7.  RE: Invoke Script Output Issues

    Posted May 31, 2018 08:50 AM

    sure,

    you mean this

    *EDIT*, that was meant to be a txt file. Why did it zip it? I've also attached the actual script



  • 8.  RE: Invoke Script Output Issues

    Posted May 31, 2018 09:09 AM

    Thanks, attachments are always zipped.

    Wondering why you get the output in this compressed format.

    That is also the reason why my RegEx doesn't work for you.

    In my testing the output appears as

    Number Friendly Name                            Operationa Total Size Partition

                                                    lStatus                Style  

    ------ -------------                            ---------- ---------- ---------

    1      VMware Virtual disk SCSI Disk Device     Online           2 GB MBR     

    0      VMware Virtual disk SCSI Disk Device     Online          60 GB MBR     

    10     VMware Virtual disk SCSI Disk Device     Online          40 GB MBR     

    7      VMware Virtual disk SCSI Disk Device     Offline         30 GB MBR


    Is the line-width on that target station set to a specific value?
    What is the content of $Host.UI.RawUI?

    You can eventually try to change it with

    $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)



  • 9.  RE: Invoke Script Output Issues

    Posted May 31, 2018 11:17 PM

    Hmm, something seems wrong. Will investigate.

    PS C:\WINDOWS\system32> $Host.UI.RawUI

    ForegroundColor       : DarkYellow

    BackgroundColor       : DarkMagenta

    CursorPosition        : 0,61

    WindowPosition        : 0,13

    CursorSize            : 25

    BufferSize            : 120,3000

    WindowSize            : 120,50

    MaxWindowSize         : 120,73

    MaxPhysicalWindowSize : 274,73

    KeyAvailable          : False

    WindowTitle           : Administrator: Windows PowerShell

    PS C:\WINDOWS\system32> $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)

    Exception setting "BufferSize": "Cannot set the buffer size because the size specified is too large or too small.

    Parameter name: value

    Actual value was 500,25."

    At line:1 char:1

    + $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Siz ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException

        + FullyQualifiedErrorId : ExceptionWhenSetting



  • 10.  RE: Invoke Script Output Issues

    Posted May 31, 2018 11:53 PM

    Is that from the station where you run the Get-Disk, or from the station from where you run the Invoke-VMScript?



  • 11.  RE: Invoke Script Output Issues

    Posted Jun 01, 2018 12:09 AM

    Station,You mean like laptop? yes,

    That was just form the Powershell window. Here is the ISE version

    PS C:\WINDOWS\system32>  $Host.UI.RawUI

    ForegroundColor       : -1

    BackgroundColor       : -1

    CursorPosition        : 0,0

    WindowPosition        :

    CursorSize            :

    BufferSize            : 181,0

    WindowSize            :

    MaxWindowSize         :

    MaxPhysicalWindowSize :

    KeyAvailable          :

    WindowTitle           : Administrator: Windows PowerShell ISE

    PS C:\WINDOWS\system32>  $Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)

    PS C:\WINDOWS\system32> $result.ScriptOutput

    Number F Serial Number                    HealthStatus         OperationalStatu

           r                                                       s              

           i                                                                      

           e                                                                      

           n                                                                      

           d                                                                      

           l                                                                      

           y                                                                      

                                                                                  

           N                                                                      

           a                                                                      

           m                                                                      

           e                                                                      

    ------ - -------------                    ------------         ----------------

    0      V                                  Healthy              Online         

    1      V                                  Healthy              Online         

    2      V                                  Healthy              Online         

    3      V                                  Healthy              Online         

    4      V                                  Healthy              Online         

    PS C:\WINDOWS\system32>



  • 12.  RE: Invoke Script Output Issues

    Posted Jun 01, 2018 06:15 AM

    No, I mean on the VM, the one where you run the Get-Disk.
    Just display the content of $Host.UI.RawUI with Invoke-VMScript.
    That's most probably where the settings make the output such a compressed format.



  • 13.  RE: Invoke Script Output Issues

    Posted Jun 04, 2018 01:15 AM

    Ok, So when i run the 'Get-Disk' localy on the VM it outputs the correctly. However when I do it via an Invoke it outputs the messed up version.

    The top output is from the VM's console. The bottom is from my PC.



  • 14.  RE: Invoke Script Output Issues

    Posted Jun 04, 2018 07:44 AM

    Can you try sending the following instead?

    Get-Disk | Out-String -Width 132



  • 15.  RE: Invoke Script Output Issues

    Posted May 31, 2018 08:48 AM

    Tried to change the status to OperationalStatus