VMware Cloud Community
Mallik7
Enthusiast
Enthusiast
Jump to solution

I'm looking for a PowerCLI script that helps to determine the current status of the vmtools and vm hardware version which the servers list can grab from the input file, can some one help please.

I'm looking for a PowerCLI script that helps to determine the current status of the vmtools and vm hardware version which the servers list can grab from the input file, can some one help please - thanks

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Do you mean like this?

$vcNames = 'vc1','vc2','vc3'

Connect-VIServer -Server $vcNames

$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'

Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |

Select Name,

    @{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}},

    @{N="HW Version";E={$_.Config.version}},

    @{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},

    @{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}} |

Group-Object -Property vCenter | %{

    $_.Group |

    Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture

}


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

View solution in original post

15 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this.

The input file should have 1 name per line.

$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'

Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |

Select Name,

    @{N="HW Version";E={$_.Config.version}},

    @{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},

    @{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}}  


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

0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

thanks LucD, forgot to mention that, I need to connect multiple vCenters before I run this script and also that output should be saved in .csv format with the running date, time to be captured in the file name. (example: vcentername-03032018-10:30am.csv)

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And is the list of names in the input file over multiple vCenters?


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Do you mean like this?

$vcNames = 'vc1','vc2','vc3'

Connect-VIServer -Server $vcNames

$vmNames = (Get-Content -Path .\vmnames.txt) -join '|'

Get-View -ViewType VirtualMachine -Filter @{'Name'=$vmNames} |

Select Name,

    @{N='vCenter';E={([uri]$_.Client.ServiceUrl).Host}},

    @{N="HW Version";E={$_.Config.version}},

    @{N='VMware Toos Status';E={$_.Guest.ToolsStatus}},

    @{N="VMware Tools version";E={$_.Config.Tools.ToolsVersion}} |

Group-Object -Property vCenter | %{

    $_.Group |

    Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture

}


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

Mallik7
Enthusiast
Enthusiast
Jump to solution

yes, the list of servers that I'm going add to the input file are from different vCenters.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

See my last code snippet


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

0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

excellent, thanks much and that helps.

However, if any server that is not available in any vCenter that has connected to, it should list out as 'Not Found". Can you please add that step as well.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That requires a slightly different logic in the code, try like this

$vcNames = 'vc1','vc2','vc3'

Connect-VIServer -Server $vcNames

$report = foreach($vmName in (Get-Content -Path .\vmnames.txt)){

    Try{

        $vm = Get-VM -Name $vmName -ErrorAction Stop

        New-Object PSObject -Property @{

            Name = $vmName

            vCenter = ([uri]$vm.ExtensionData.Client.ServiceUrl).Host

            'VMware Tools Status' = $vm.ExtensionData.Guest.ToolsStatus

            'VMware Tools version' = $vm.ExtensionData.Config.Tools.ToolsVersion

        }

    }

    Catch{

        New-Object PSObject -Property @{

            Name = $vmName

            vCenter = 'Not found'

            'VMware Tools Status' = ''

            'VMware Tools version' = ''

        }

    }

}

$report |

Group-Object -Property vCenter | %{

    $_.Group |

    Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture

}


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

0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

sorry, the logic not working.

It is creating 3 different files with the each vCenter name that I connect and also creating a file as "not found".

can you look at the script again and correct it

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Euh, isn't that what you asked in the beginning, a file per vCenter?

And since we now introduced 'not found', that would be an additional file.


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

0 Kudos
cloudtrainer
Contributor
Contributor
Jump to solution

Hi Lucd, How to make a loop to wait until the VM get its VMWare tools running? I want the code to wait for 30 seconds before it try for next check for vmware tools on given vm input. Or should repeat for max 10 times before coming out with fail status. Is it possible? I am new to Powershell, so wondering if that is a simple ask or difficult one?
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that is possible, but can you perhaps create a new thread for this.
Your question is quite different from the original one in this thread.


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

0 Kudos
aryajp
Contributor
Contributor
Jump to solution

Hi LucD, I'm looking for a PowerCLI script that helps to determine the Hardware address of vms which can be grabed from the input file. Please help.
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Please don't hijack existing threads for your question, you can just open a new thread.
And don't cross-post, repeating your question in multiple threads in the same community will not give you a reply faster.


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

0 Kudos
santoshannie
Contributor
Contributor
Jump to solution

$vcNames = 'vc1','vc2','vc3'

Connect-VIServer -Server $vcNames

$report = foreach($vmName in (Get-Content -Path .\vmnames.txt)){

    Try{

        $vm = Get-VM -Name $vmName -ErrorAction Stop

        New-Object PSObject -Property @{

            Name = $vmName

            vCenter = ([uri]$vm.ExtensionData.Client.ServiceUrl).Host

            'VMware Tools Status' = $vm.ExtensionData.Guest.ToolsStatus

            'VMware Tools version' = $vm.ExtensionData.Config.Tools.ToolsVersion

        }

    }

    Catch{

        New-Object PSObject -Property @{

            Name = $vmName

            vCenter = 'Not found'

            'VMware Tools Status' = ''

            'VMware Tools version' = ''

        }

    }

}

$report |

Group-Object -Property vCenter | %{

    $_.Group |

    Export-Csv -Path ".\$($_.Name)-$(Get-Date -Format 'ddMMyyyy-HHmm').csv" -NoTypeInformation -UseCulture

}

I require Guest OS version as well

0 Kudos