PowerCLI

 View Only
Expand all | Collapse all

Script to verify activation of VM Windows License

  • 1.  Script to verify activation of VM Windows License

    Posted Dec 28, 2017 05:44 PM

    I have deployed over 50 VM's via powercli Script and noticed the customization on some of the VM's didn't activate windows license. Is it possible to run a powercli script on these 50 VM's to see which VM's completed with windows activated or not? This would save loads of time without having to check every VM individually. 



  • 2.  RE: Script to verify activation of VM Windows License

    Posted Dec 28, 2017 05:48 PM


  • 3.  RE: Script to verify activation of VM Windows License

    Posted Dec 28, 2017 06:13 PM

    There are two options, depending on what is available on these VMs.
    Is the guest OS of these VMs reachable over the network?

    If yes, you can use a remote Get-CimInstance call to retrieve the activation status

    Get-CimInstance -ClassName SoftwareLicensingProduct -ComputerName $name |

        Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |

        Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",

        "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}}

             

    Do these VMs have VMware Tools installed?

    If yes, You can use Invoke-VMScript to run the same Get-CimInstance call directly inside the guest OS on the VM.

    $code = @"

    Get-CimInstance -ClassName SoftwareLicensingProduct |

        Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |

        Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",

        "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}}

    "@

    Invoke-VMScript -VM $vm -ScriptText $code



  • 4.  RE: Script to verify activation of VM Windows License

    Posted Jan 08, 2018 02:59 PM

    Hi LucD, This is the error message I'm getting.

    PowerCLI C:\> Invoke-VMScript -VM $vm -ScriptText $code

    WARNING: This property is deprecated and will be removed in a following release. It has been added for backwards compatibility with the string class

    that the Invoke-VMScript cmdlet used to return. Use the 'ScriptOutput' property instead.

    ScriptOutput

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

    |  At line:4 char:70

    |  +     "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[]}}}

    |  +                                                                      ~

    |  Array index expression is missing or not valid.

    |      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx

    |     ception

    |      + FullyQualifiedErrorId : MissingArrayIndexExpression

    |

    |

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



  • 5.  RE: Script to verify activation of VM Windows License

    Posted Jan 08, 2018 04:46 PM

    My bad, that should have been single quotes.

    $code = @'

    Get-CimInstance -ClassName SoftwareLicensingProduct |

        Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |

        Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",

        "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}}

    '@

    Invoke-VMScript -VM $vm -ScriptText $code



  • 6.  RE: Script to verify activation of VM Windows License

    Posted Jan 08, 2018 04:54 PM

    No worries :-). I'm now getting an access denied error.  Would I need to provide some credentials per the guest OS?

    ScriptOutput

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

    |  Get-CimInstance : Access denied

    |  At line:1 char:4

    |  + & {Get-CimInstance -ClassName SoftwareLicensingProduct |

    |  +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    |      + CategoryInfo          : PermissionDenied: (root\cimv2:SoftwareLicensingP

    |     roduct:String) [Get-CimInstance], CimException

    |      + FullyQualifiedErrorId : HRESULT 0x80041003,Microsoft.Management.Infrastr

    |     ucture.CimCmdlets.GetCimInstanceCommand

    |

    |



  • 7.  RE: Script to verify activation of VM Windows License
    Best Answer

    Posted Jan 08, 2018 05:00 PM

    If the account under which you run the script, has the required rights inside the guest OS on the VM, you don't need to provide credentials.

    If that is not the case, then you need to provide the guest credentials on the Invoke-VMScript cmdlet.



  • 8.  RE: Script to verify activation of VM Windows License

    Posted Jan 07, 2019 02:58 PM

    Hi Lucd,

    I need to run the script for multiple VMs and export the output as text file or csv file.

    Could you please help for the same.. I am able to run the script for multiple VMs but unable to export the output for each VM.



  • 9.  RE: Script to verify activation of VM Windows License

    Posted Jan 07, 2019 03:57 PM

    Try something like this.
    You can change the Get-VM to whatever VM selection you want.

    $code = @'

    Get-CimInstance -ClassName SoftwareLicensingProduct |

      Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |

      Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",

      "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}} |

      ConvertTo-Csv -NoTypeInformation

    '@


    $report = @()


    Get-VM |

       ForEach-Object -Process {

       $result = Invoke-VMScript -VM $_ -ScriptText $code

       $line = $result.ScriptOutput | ConvertFrom-Csv

       Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty

       $report += $line

    }


    $report



  • 10.  RE: Script to verify activation of VM Windows License

    Posted Jan 07, 2019 04:35 PM

    Thanks a lot Lucd. I have modified it slightly as below and getting the desired output but in between it throws error as ConvertFrom-Csv : Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Provide an argument that is not null or empty:-

    $code = @'

     Get-CimInstance -ClassName SoftwareLicensingProduct |

      Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |

      Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",

      "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}} |

      ConvertTo-Csv -NoTypeInformation

    '@

    $report = @()

    $cred= Get-Credential Administrator

    Get-VM (get-content ./servers.txt) |

       ForEach-Object -Process {

       $result = Invoke-VMScript -VM $_ -ScriptText $code -Verbose -GuestCredential $cred

       $line = $result.ScriptOutput | ConvertFrom-Csv

       Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty

       $report += $line

    }

    $report | export-csv c:\activation.csv

    $code = @'
     
    Get-CimInstance -ClassName SoftwareLicensingProduct |
     
      Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} |
     
      Select @{N='LicenseStatus';E={@("Unlicensed","Licensed","OOB Grace",
     
      "OOT Grace","Non-Genuine Grace","Notification","Extended Grace")[$($_.LicenseStatus)]}} |
     
      ConvertTo-Csv -NoTypeInformation
     
    '@
     
    $report = @()
    $cred= Get-Credential Administrator
    Get-VM (get-content ./servers.txt) |
       ForEach-Object -Process {
     
       $result = Invoke-VMScript -VM $_ -ScriptText $code -Verbose -GuestCredential $cred
       $line = $result.ScriptOutput | ConvertFrom-Csv
     
       Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty
     
       $report += $line
     
    }
    $report | export-csv c:\activation.csv


  • 11.  RE: Script to verify activation of VM Windows License

    Posted Jan 07, 2019 05:00 PM

    It could be that there are VMs that are not returning information, which would explain the error message.

    You could do a test on the $result.ScriptOutput to check if it contais the required info, before feeding it to ConvertFrom-Csv



  • 12.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 09:04 AM

    Thanks for the code above, I was able to use it for something else (getting Video Graphic driver and its version for Horizon VDIs). But I would like to have for each line of the driver, also the VM Name, so I know where to look after. However this VM value is not exported to CSV File. I am not very familiar with Add-Member for input stream, what could be wrong here?

    # get drivers info over VMTools
    $code = @'
    Get-CimInstance -ClassName Win32_VideoController |
    Select-Object -Property DeviceID, Caption, InfFilename, DriverVersion, DriverDate, PNPDeviceID |
    ConvertTo-Csv -NoTypeInformation
    '@
    
    $report = @()
    
    $vms = "c:\temp\horizon_VDIs_Agent01.csv"
    
    Get-VM (Get-Content $vms) |
    ForEach-Object -Process {
    $result = Invoke-VMScript -VM $_ -GuestCredential $xcredential -ScriptType PowerShell -ScriptText $code -Verbose
    $line = $result.ScriptOutput | ConvertFrom-Csv
    Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty
    $report += $line
    }
    
    $report | export-csv c:\Temp\Horizon_drivers01.csv

    Output looks like this below:

    "VideoController1","VMware Horizon Indirect Display Driver","oem15.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000"
    "VideoController2","Microsoft Basic Display Adapter","display.inf","10.0.18362.1","21.06.2006 02:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78"
    "VideoController1","VMware Horizon Indirect Display Driver","oem16.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000"
    "VideoController2","VMware SVGA 3D","oem19.inf","8.16.7.8","14.05.2020 02:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78"
    "VideoController1","VMware Horizon Indirect Display Driver","oem15.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000"
    "VideoController2","VMware SVGA 3D","oem11.inf","8.17.2.14","08.02.2021 01:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78"

    As you can see there is "Microsoft Basic Display Adapter" which got installed after the Horizon Agent update, which is wrong,



  • 13.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 10:30 AM

    That Add-Member looks ok.

    Is that the content of the CSV?
    There are no column headers



  • 14.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 10:36 AM

    It is, I just did not copy it with the rest. This is how the first line looks like:

     

     

    #TYPE System.Management.Automation.PSCustomObject
    "DeviceID","Caption","InfFilename","DriverVersion","DriverDate","PNPDeviceID"
    "VideoController1","VMware Horizon Indirect Display Driver","oem15.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000"
    "VideoController2","VMware SVGA 3D","oem17.inf","8.16.7.8","14.05.2020 02:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78"

     

     

     

    If the Add-Member looks fine, where the VM part is gone? Should it not been at the beginning of each line?



  • 15.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 10:49 AM

    Not sure, but I just ran the script myself, and for me, it working (the VM name is included in the CSV).

    I noticed you used Get-Content on a CSV file, instead of a TXT file in the original script.
    Is that really a CSV file (including column headers)?




  • 16.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 11:14 AM

    Not really an CSV, just File without any column headers, VDI VM Name each in new row.

    Actually plan was to use something like this as input:

    $report = @()
    Get-Folder -Id "Folder-group-v84" | Get-VM |
       ForEach-Object -Process {
       $result = Invoke-VMScript -VM $_ -GuestCredential $xcredential -ScriptType PowerShell -ScriptText $code -Verbose
       $line = $result.ScriptOutput | ConvertFrom-Csv
       Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty
       $report += $line
    
    }
    $report | export-csv c:\Temp\Horizon_VDIs02.csv

     

    But the CSV Output is still without VM:

    #TYPE System.Management.Automation.PSCustomObject
    "DeviceID","Caption","InfFilename","DriverVersion","DriverDate","PNPDeviceID"
    "VideoController1","VMware Horizon Indirect Display Driver","oem16.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000"
    "VideoController2","Microsoft Basic Display Adapter","display.inf","10.0.18362.1","21.06.2006 02:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78"

     

     

    I am using:

    $PSVersionTable
    
    Name                           Value                                                                                                                                                          
    ----                           -----                                                                                                                                                          
    PSVersion                      5.1.18362.1801                                                                                                                                                 
    PSEdition                      Desktop                                                                                                                                                        
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
    BuildVersion                   10.0.18362.1801                                                                                                                                                
    CLRVersion                     4.0.30319.42000                                                                                                                                                
    WSManStackVersion              3.0                                                                                                                                                            
    PSRemotingProtocolVersion      2.3                                                                                                                                                            
    SerializationVersion           1.1.0.1 
    
    VMware PowerCLI 12.4.0 build 18627050


  • 17.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 11:21 AM

    Did you also check the content of the $report variable?
    Is the VM property missing there as well?
    You can also check with a Get-Member

    $report | Get-Member


  • 18.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 12:08 PM

    I did not check it before, but seems missing also there:

    $report | Get-Member
    
    
       TypeName: System.Management.Automation.PSCustomObject
    
    Name          MemberType   Definition                                           
    ----          ----------   ----------                                           
    Equals        Method       bool Equals(System.Object obj)                       
    GetHashCode   Method       int GetHashCode()                                    
    GetType       Method       type GetType()                                       
    ToString      Method       string ToString()                                    
    Caption       NoteProperty string Caption=VMware Horizon Indirect Display Driver
    DeviceID      NoteProperty string DeviceID=VideoController1                     
    DriverDate    NoteProperty string DriverDate=08.09.2020 02:00:00                
    DriverVersion NoteProperty string DriverVersion=1.4.12.0                        
    InfFilename   NoteProperty string InfFilename=oem16.inf                         
    PNPDeviceID   NoteProperty string PNPDeviceID=ROOT\VMWVIDD\0000  


  • 19.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 12:19 PM

    I don't see what is wrong.
    I used the exact same code, and for me, it works.
    I suggest to run the script step-by-step in a debugger (like VSC for example), and check what is in the variables at each step.



  • 20.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 06:43 PM

    I tried to debug it with Microsoft ISE but somehow for me this Add-Member does not do anything. Can the problem be that I get two Line InputObject?

     

    [DBG]: PS C:\scripts>> $line
    
    
    DeviceID      : VideoController1
    Caption       : VMware Horizon Indirect Display Driver
    InfFilename   : oem16.inf
    DriverVersion : 1.4.12.0
    DriverDate    : 08.09.2020 02:00:00
    PNPDeviceID   : ROOT\VMWVIDD\0000
    
    DeviceID      : VideoController2
    Caption       : Microsoft Basic Display Adapter
    InfFilename   : display.inf
    DriverVersion : 10.0.18362.1
    DriverDate    : 21.06.2006 02:00:00
    PNPDeviceID   : PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78
    
    
    
    
    [DBG]: PS C:\2backup\scripts>> $_.Name
    VDI0001
    
    [DBG]: PS C:\scripts>> Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty
    
    [DBG]: PS C:\scripts>> $line
    
    
    DeviceID      : VideoController1
    Caption       : VMware Horizon Indirect Display Driver
    InfFilename   : oem16.inf
    DriverVersion : 1.4.12.0
    DriverDate    : 08.09.2020 02:00:00
    PNPDeviceID   : ROOT\VMWVIDD\0000
    
    DeviceID      : VideoController2
    Caption       : Microsoft Basic Display Adapter
    InfFilename   : display.inf
    DriverVersion : 10.0.18362.1
    DriverDate    : 21.06.2006 02:00:00
    PNPDeviceID   : PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78
    
    
    
    
    [DBG]: PS C:\scripts>> 

     

    If I try to Add-Member again, i get error below:

    [DBG]: PS C:\scripts>> Add-Member -InputObject $line -Name VM -Value $_.Name -MemberType NoteProperty
    Add-Member : Cannot add an item named "VM" because an item with that name already exists. To overwrite the element anyway, add the Command to the Force parameter. 

     

     

    Sorry if this is OT, you could if desired move my question to new topic. Tomorrow I'll try it with PowerShell 7 (7.1.5)



  • 21.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 06:45 PM

    Yes, if you have 2 objects in $line, that means you have an array.
    In that case you will have to loop through the array, and add the new property on each element in the array.

    Testing in PSv7 will not make a difference in this case



  • 22.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 06:47 PM

    Seems my problem is array as InputObject, so need to do it with $line[0] till $line[n]  in Add-Member

     



  • 23.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 06:51 PM

    Try something like this 

     

    $line = $result.ScriptOutput | ConvertFrom-Csv
    $vmName = $_.Name
    $line = $line | Foreach-Object -Process {
      Add-Member -InputObject $_ -Name VM -Value $vmName -MemberType NoteProperty -PassThru
    }
    $report += $line

     



  • 24.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 07:03 PM

    The $report Variable is now with your example empty. Isn't the new code on line 3 the one which overrides the $line input itself? Also the $report | Get-Member give me the "You must supply an object to the Get-Member cmdlet " error.



  • 25.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 07:11 PM

    My bad, I forgot the PassThru switch



  • 26.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 07:24 PM

    Now it works as it should.. Kudos to your support on this Add-Member issue at my side. I really appreciate it.

    Last question in regards to it. Is it possible to add new object VM to the beginning of the line?

    The output (shorten to just few line) looks like this now:

    #TYPE System.Management.Automation.PSCustomObject
    "DeviceID","Caption","InfFilename","DriverVersion","DriverDate","PNPDeviceID","VM"
    "VideoController1","VMware Horizon Indirect Display Driver","oem16.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000","VDI0001"
    "VideoController2","Microsoft Basic Display Adapter","display.inf","10.0.18362.1","21.06.2006 02:00:00","PCI\VEN_15AD&DEV_0405&SUBSYS_040515AD&REV_00\3&61AAA01&0&78","VDI0001"
    "VideoController1","VMware Horizon Indirect Display Driver","oem18.inf","1.4.12.0","08.09.2020 02:00:00","ROOT\VMWVIDD\0000","VDI0002"

     



  • 27.  RE: Script to verify activation of VM Windows License

    Posted Oct 18, 2021 08:06 PM

    You can do a Select-Object with the properties in the order you want and pipe the output to Export-Csv.



  • 28.  RE: Script to verify activation of VM Windows License

    Posted Oct 19, 2021 08:27 AM

    Thanks a lot, everything is working fine.



  • 29.  RE: Script to verify activation of VM Windows License

    Posted Oct 21, 2021 01:57 PM

    Do you know maybe if the Invoke-VMScript can be used with "ForEach-Object -Parallel" which was introduced with PowerShell 7 and PowerCLI 12.2 ?

    I was reading the PowerCLI 12.2 Release Note [1] and the "Inline -Server parameter" or "Use PowerCLI Context", but both of these I am unable to use with the script on link [2].

    I would like to make Invoke-VMScript script faster, as it takes a lot of time to execute in Environment with 100+ VMs (VDIs)

     

    [1] https://blogs.vmware.com/PowerCLI/2021/02/new-release-vmware-powercli-12-2.html
    [2] https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Script-to-verify-activation-of-VM-Windows-License/m-p/2872639/highlight/true#M103756

     



  • 30.  RE: Script to verify activation of VM Windows License

    Posted Oct 21, 2021 02:07 PM

     wrote:

    ... but both of these I am unable to use with the script ...

     


    How did you try to use that feature, and what is the issue you encounter?



  • 31.  RE: Script to verify activation of VM Windows License

    Posted Oct 21, 2021 09:05 PM

    I tried to do the "Inline -Server parameter" way.

    script:

    # Establish connection to vCenter
    $vcserver = Connect-VIServer -Server $vc -Credential $xcredential
     
    $code = @'
     
     Get-CimInstance -ClassName Win32_VideoController |
    
      Select-Object -Property DeviceID, Caption, InfFilename, DriverVersion, DriverDate, PNPDeviceID |
    
      ConvertTo-Csv -NoTypeInformation
    
    '@
    
    $report = @()
    
    # ForEach-Object -Parallel
    Get-Folder -Id "Folder-group-v101" | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn" -and $_.GuestId -eq 'windows9_64Guest' -and $_.Guest.State -eq "Running" } |
      ForEach-Object -Parallel {
        $result = Invoke-VMScript -Server $using:vcserver -VM $_ -GuestCredential $xcredential -ScriptType PowerShell -ScriptText $code
        $line = $result.ScriptOutput | ConvertFrom-Csv
        $vmName = $_.Name
        $line = $line | Foreach-Object -Process {
          Add-Member -InputObject $_ -Name VM -Value $vmName -MemberType NoteProperty -PassThru
        }
        $report += $line
    }
    
    $report | Select-Object "VM","DeviceID","Caption","InfFilename","DriverVersion","DriverDate","PNPDeviceID" | 
        Export-Csv -NoTypeInformation -Path "c:\Temp\Horizon_VDIs03.csv"

     

    It complains about ScriptText is missing, which is somehow weird, If i put instead -Parallel the -Process, and remove from Invoke-VMScript this "-Server $using:vcserver", it works fine (PowerShell 7.1.5)

    PS C:\scripts> Measure-Command { .\Horizon_Get-SVGA_Drivers.ps1 | Out-Default }
    Invoke-VMScript:
    Line |
       2 |  …   $result = Invoke-VMScript -Server $using:vcserver -VM $_ -GuestCred …
         |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | 21.10.2021 22:44:42      Invoke-VMScript         Value cannot be found for the mandatory parameter ScriptText
    ConvertFrom-Csv:

     

    I did not find much information about "$using:**" variable so that above is copy/paste from release note page.



  • 32.  RE: Script to verify activation of VM Windows License

    Posted Oct 22, 2021 06:29 AM

    Since you define the $code variable outside the Foreach -Parallel block, you will also refer to it with $using:



  • 33.  RE: Script to verify activation of VM Windows License

    Posted Oct 22, 2021 08:12 AM

    I changed the Invoke-VMScript line to

     

    $result = Invoke-VMScript -Server $using:vcserver -VM $_ -GuestCredential $using:xcredential -ScriptType PowerShell -ScriptText $using:code

     

    (GuestCredentials and $code are now added to that line).

    Now that error above is gone, but $report seems empty as the output file is 0 bytes. I'll try to debug this, there is no new error shown.



  • 34.  RE: Script to verify activation of VM Windows License

    Posted Oct 22, 2021 08:15 AM

    The $report variable is also defined outside the Foreach block



  • 35.  RE: Script to verify activation of VM Windows License

    Posted Oct 22, 2021 09:57 AM

    Sure but it gets input from $line, and the line from $result of Invoke-VMScript. I am not quite sure what to use with $report that it gets the input from ForEach block?



  • 36.  RE: Script to verify activation of VM Windows License

    Posted Oct 22, 2021 10:47 AM

    You can also just place the result on the pipeline, and assign all that to a variable

    $result = Foreach-Object -Parallel {
      # The code to be executed in parallel
      $line
    }