Highlighted
Contributor
Contributor

Get Guestos trough Powercli

Jump to solution

Hi all,

I wrote below script to get all Vm's in my Vcenters that don't have vmware tools installed. i am trying to include the vm's / guests operating system into the csv output as well and can't seem to figure out how to do this. So if someone could help me out that would be great!

New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine ` -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' ` -Force

New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine ` -ValueFromExtensionProperty 'Config.tools.ToolsVersion' ` -Force

$vcenter=Read-Host "Please enter VCenter to run this report on"

$csvlocation=Read-Host "Please enter a location for the CSV logfile"

Connect-ViServer $vcenter

$notools = Get-VM | where-Object {$_.ToolsVersionStatus -eq "guestToolsNotInstalled"}

if ( $notools -eq $null) {

exit

}

else {

Get-VM $notools | Select Name, Version, ToolsVersion, ToolsVersionStatus, powerstate, vmhost, | Export-Csv -NoTypeInformation -UseCulture $csvlocation\$vcenter.csv

}

Disconnect-VIServer $vcenter -Confirm:$False

Thanks in advanceSmiley Happy

1 Solution

Accepted Solutions
Highlighted
Expert
Expert

Hello, -

You can access such info via a sub-property in the Guest property of the VirtualMachine object.  So, to continue with your New-VIProperty usage, you could add another new VIProperty as follows, then add that property to the Select statement:

New-VIProperty -Name GuestFullName -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.GuestFullName' -Force

Then just add "GuestFullName" to the list of properties in your Select statement, and you should be good.  That do it for you?

View solution in original post

0 Kudos
6 Replies
Highlighted
Expert
Expert

Hello, -

You can access such info via a sub-property in the Guest property of the VirtualMachine object.  So, to continue with your New-VIProperty usage, you could add another new VIProperty as follows, then add that property to the Select statement:

New-VIProperty -Name GuestFullName -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.GuestFullName' -Force

Then just add "GuestFullName" to the list of properties in your Select statement, and you should be good.  That do it for you?

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Thanks for the help, this sort off did the trick. Some vm's are not showing their os version but that is not because of the new vi property.

Going to try and figure out why that is now Smiley Happy

0 Kudos
Highlighted
Expert
Expert

Hello, mkool89-

Alright, good, glad to help.  As for VMs not showing their OS version -- that is reliant upon VMware Tools running in the guest.  So, if Tools aren't running (or haven't been for a while), you might see the symptom of no data for that Guest OS property.  Do the VMs in your example that return no OS info also not have Tools running?

0 Kudos
Highlighted
Contributor
Contributor

mattboren,

I didn't know that the property was dependandt on vmwaretools being installed. It makes sense now that it doesn't display since my script displays all VM's withouth tools installed! At least i learned something Smiley Happy !

I have one more question: is there a place where i can see al the viproperty's that can be added? I am having dificulties with finding  properties and what they do.

Thanks

0 Kudos
Highlighted
Expert
Expert

Hello-

Yesss, good to hear (I learn at least one thing every day!).

As for a place to see what VIProperties can be added:  it's really about what properties are available.  The vSphere API reference documentation shows all of the properties/methods that you can leverage.  vSphere Web Services SDK:  http://www.vmware.com/support/developer/vc-sdk/.  And, in particular, the vSphere API Reference:  http://pubs.vmware.com/vsphere-55/topic/com.vmware.wssdk.apiref.doc/right-pane.html.

Check those out, and made whatever VIProperties you want!  Meanwhile, LucD (of course) has a nice collection of VIProperties that he and others have written:  http://www.lucd.info/viproperties/.  Check it out.

0 Kudos
Highlighted
Contributor
Contributor

Hi,

Im trying to do something similar, but im running into some problems tho.

First of all, i would like to just count how many VM's are running linux as guest OS, this i have done by using this command:

Get-VM | Select-Object Name, PowerState, NumCpu, MemoryMB, ProvisionedSpaceGB, Guest | Where-Object {$_.Guest.OSFullName -like "*Linux*"}

And i get list back of 6 VM's but when i go to my vSphere Client and list all VM's, filter them on GuestOS containing Linux, i have 14 VM's

Why are the Powershell CLI only counting 6, when there are 14 in total? Does this also have something to do with vmWare Tools not running on the VM's? or is this something else?

Edit:

I solved it. I belive its because the above line does not look at what the VM's OS have been selected to be the time it was build. But that is only what i belive Smiley Happy

I solved it with this instead:

$vms = get-vm

foreach($vm in $vms) {

$vmview = $vm | get-view

if ($vmview.Summary.Config.GuestFullName -like "*Windows*") {$wincount++}

}

$wincount

This will count the real amount of VM's that have some kind of Windows OS configured.

Message was edited by: GlenTrust