VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to get the failed VM details

Hi,

I am getting the below errors using the script for few VMs and I am unable to identify the VM Name for the failed ones.

Please help.

Error

Invoke-VMScript : 06/23/2020 7:03:54 AM Invoke-VMScript     A general system error occurred: vix error codes = (1, 0).

At D:\myreports\Processor_Info\Processor_Info_3.0.ps1:57 char:15

+ $result = Invoke-VMScript @sInvoke
+           ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo      : NotSpecified: (:) [Invoke-VMScript], SystemError

+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Invoke-VMScript : 06/23/2020 7:03:25 AM Invoke-VMScript     Failed to authenticate with the guest operating system using the supplied credentials.

At D:\myreports\Processor_Info\Processor_Info_3.0.ps1:57 char:15

+ $result = Invoke-VMScript @sInvoke
+           ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo      : NotSpecified: (:) [Invoke-VMScript], InvalidGuestLogin
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.InvokeVmScript

Script.

Get-Folder DEV | get-vm | Where{$_.'PowerState' -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'windows'} | select 'Folder', 'Name',

@{N="IP_Address";E={@($_.guest.IPAddress[0])}},

@{N="OS"; E={@($_.guest.OSFullName)}},

@{N="VM_vCPU"; E={@($_.NumCPU)}},

@{N="VM_Memory(GB)"; E={@($_.MemoryGB)}} | Export-Csv -Path $reportlocation1 -NoTypeInformation -UseCulture

$code = @'

"### Output ###"

(Get-WmiObject Win32_ComputerSystem NumberOfLogicalProcessors).NumberOfLogicalProcessors

"### Output ###"

((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory/1GB).ToString("N0")

'@

$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, $out2 = $result.ScriptOutput -split '### Output ###'

    $out1 = $out1.TrimStart("`n`r")

    $out2 = $out2.TrimStart("`n`r")

    $report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS_CPU' -Value ([int]$out1) -PassThru |

        Add-Member -MemberType NoteProperty -Name 'OS_Memory' -Value ([int]$out2) -PassThru

}

$report1 | Export-Csv -Force -Path $reportlocation1 -UseCulture -NoTypeInformation

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could use a try-catch construct.

Get-Folder DEV | get-vm | Where{$_.'PowerState' -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'windows'} | select 'Folder', 'Name',

@{N="IP_Address";E={@($_.guest.IPAddress[0])}},

@{N="OS"; E={@($_.guest.OSFullName)}},

@{N="VM_vCPU"; E={@($_.NumCPU)}},

@{N="VM_Memory(GB)"; E={@($_.MemoryGB)}} | Export-Csv -Path $reportlocation1 -NoTypeInformation -UseCulture


$code = @'

"### Output ###"

(Get-WmiObject Win32_ComputerSystem NumberOfLogicalProcessors).NumberOfLogicalProcessors

"### Output ###"

((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory/1GB).ToString("N0")

'@


$report1 = @()

Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

ForEach-Object -Process {

    $sInvoke = @{

        VM              = $_.Name

        GuestCredential = $Creds

        ScriptTYpe      = 'powershell'

        ScriptText      = $code

        ErrorAction = 'Stop'

    }

    try{

        $result = Invoke-VMScript @sInvoke

        $dummy, $out1, $out2 = $result.ScriptOutput -split '### Output ###'

        $out1 = $out1.TrimStart("`n`r")

        $out2 = $out2.TrimStart("`n`r")

        $report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS_CPU' -Value ([int]$out1) -PassThru |

            Add-Member -MemberType NoteProperty -Name 'OS_Memory' -Value ([int]$out2) -PassThru

    }

    catch{

        Throw "Failed for $($row.Name)"

    }

}


$report1 | Export-Csv -Force -Path $reportlocation1 -UseCulture -NoTypeInformation


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You could use a try-catch construct.

Get-Folder DEV | get-vm | Where{$_.'PowerState' -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'windows'} | select 'Folder', 'Name',

@{N="IP_Address";E={@($_.guest.IPAddress[0])}},

@{N="OS"; E={@($_.guest.OSFullName)}},

@{N="VM_vCPU"; E={@($_.NumCPU)}},

@{N="VM_Memory(GB)"; E={@($_.MemoryGB)}} | Export-Csv -Path $reportlocation1 -NoTypeInformation -UseCulture


$code = @'

"### Output ###"

(Get-WmiObject Win32_ComputerSystem NumberOfLogicalProcessors).NumberOfLogicalProcessors

"### Output ###"

((Get-WmiObject Win32_ComputerSystem).TotalPhysicalMemory/1GB).ToString("N0")

'@


$report1 = @()

Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

ForEach-Object -Process {

    $sInvoke = @{

        VM              = $_.Name

        GuestCredential = $Creds

        ScriptTYpe      = 'powershell'

        ScriptText      = $code

        ErrorAction = 'Stop'

    }

    try{

        $result = Invoke-VMScript @sInvoke

        $dummy, $out1, $out2 = $result.ScriptOutput -split '### Output ###'

        $out1 = $out1.TrimStart("`n`r")

        $out2 = $out2.TrimStart("`n`r")

        $report1 += $row | Add-Member -MemberType NoteProperty -Name 'OS_CPU' -Value ([int]$out1) -PassThru |

            Add-Member -MemberType NoteProperty -Name 'OS_Memory' -Value ([int]$out2) -PassThru

    }

    catch{

        Throw "Failed for $($row.Name)"

    }

}


$report1 | Export-Csv -Force -Path $reportlocation1 -UseCulture -NoTypeInformation


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Perfect!!! Thanks a lot LucD.

0 Kudos