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