Hi,
I am unable to get the output from invoke-vmscript as it shows blank.
Please help!!
$code = @'
"### Output ###"
$(((gcim Win32_OperatingSystem).Name).split(‘|’)[0])
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke
$dummy, $out1 = $result.ScriptOutput -split '### Output ###'
$out1 = $out1.TrimStart("`n`r") -split "`n`r"
$report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS Edition' -Value $out1 -PassThru
}
$report1 | ft -auto
Try with
$code = @'
((gcim Win32_OperatingSystem).Name).split('|')[0]
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke
$out1 = (($result.ScriptOutput.TrimStart("`n`r")) -split "`n`r")[0]
$report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS Edition' -Value $out1 -PassThru
}
#$report1 | Format-Table -auto
$report1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What are you trying to retrieve with
$(((gcim Win32_OperatingSystem -ComputerName $server.Name).Name).split(‘|’)[0])
There is no such property as Name on the returned object.
And the Computername parameter makes no sense when running this locally in the Guest OS.
And the $server variable is not initialised.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I tried as below, I am getting output
But when used the same in the script, it shows blank
But why the ComputerName with the uninitialised variable $server.Name?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I copied from the other script, I didnt notice.
$code = @'
"### Output ###"
$(((gcim Win32_OperatingSystem).Name).split(‘|’)[0])
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke | Select -ExpandProperty ScriptOutput
$dummy, $out1 = $result.ScriptOutput -split '### Output ###'
$out1 = $out1.TrimStart("`n`r") -split "`n`r"
$report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS Edition' -Value $out1 -PassThru
}
$report1 | ft -auto
Try with
$code = @'
((gcim Win32_OperatingSystem).Name).split('|')[0]
'@
$report1 = @()
Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |
ForEach-Object -Process {
$sInvoke = @{
VM = $_.Name
GuestCredential = $Creds
ScriptTYpe = 'powershell'
ScriptText = $code
}
$result = Invoke-VMScript @sInvoke
$out1 = (($result.ScriptOutput.TrimStart("`n`r")) -split "`n`r")[0]
$report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS Edition' -Value $out1 -PassThru
}
#$report1 | Format-Table -auto
$report1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That worked. Thank you very much 🙂