VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Invoke-VMScript output shows blank

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

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

I tried as below, I am getting output

ganapa2000_0-1623916399833.png

But when used the same in the script, it shows blank

0 Kudos
LucD
Leadership
Leadership
Jump to solution

But why the ComputerName with the uninitialised variable $server.Name?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked. Thank you very much 🙂

0 Kudos