This script connect to your VI Server, then retrieve all the virtual machine names and get the VMware tools status and version.

Script:

Connect-VIServer -Server VIServerName
get-vm | % { get-view $_.ID } | select Name, @{ Name="hostName"; Expression={$_.guest.hostName}}, @{ Name="ToolsStatus"; Expression={$_.guest.toolsstatus}}, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} | sort-object name

References

Connect-VIServer

Synopsis

Connects to a vSphere server.

Syntax

Connect-VIServer [-Server] <String[]> [-Port <Int32>] [-Protocol <String>] [-Credential <PSCredential>] [-User <String>] [-Password <String>] [-Session <String>] [-NotDefault] [<CommonParameters>]

Related Commands

Disconnect-VIServer

Detailed Description

Connects to a vSphere server. The cmdlet starts a new session or re-establishes a previous session with a vSphere server using the specified parameters.
You can have more than one connections to the same server. To disconnect from a server, you need to close all active connections to this server.
vSphere PowerCLI supports working with multiple default servers. If you select this option, every time when you connect to a different server using Connect-VIServer, the new server connection is stored in an array variable together with the previously connected servers, unless the -NotDefault parameter is set. This variable is named $DefaultVIServers and its initial value is an empty array. When you run a cmdlet and the target servers cannot be determined from the specified parameters, the cmdlet runs against all servers stored in the array variable. To remove a server from the $DefaultVIServers variable, you can either use Disconnect-Server to close all active connections to the server, or modify the value of $DefaultVIServers manually.

If you choose to work with a single default server, when you run a cmdlet and the target servers cannot be determined from the specified parameters, the cmdlet runs against the last connected server. This server is stored in the $defaultVIServer variable, which is updated every time you establish a new connection. Working with a single default server is deprecated and will be removed in a future release.

To switch between single and multiple default servers working mode, use the Set-PowerCLIConfiguration cmdlet.

Parameters

NAME DESCRIPTION REQUIRED? PIPELINE INPUT DEFAULT VALUE
Server Specify the IP address or the DNS name of the vSphere server to which you want to connect. true false
Port Specify the port on the server you want to use for the connection. false false
Protocol Specify the internet protocol you want to use for the connection. It can be either http or https. false false
Credential Specify a PSCredential object that contains credentials for authenticating with the server. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release. false true (ByValue)
User Specify the user name you want to use for authenticating with the server. If the -Credential parameter is also specified, this parameter is ignored. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release. false true (ByValue)
Password Specifies the password you want to use for authenticating with the server. If the -Credential parameter is also specified, this parameter is ignored. false false
Session Specify the ID of an existing vSphere server session you want to reestablish. false false
NotDefault Indicate that you do not want to include the server to which you connect into the $defaultVIServers variable. false false

Input Type

Return Type

VMware.VimAutomation.Types.VIServer

 

Get-VM

Synopsis

Retrieves the virtual machines on a vSphere server.

Syntax

Get-VM [-Datastore <Datastore[]>] [-Location <VIContainer[]>] [[-Name] <String[]>] [-Id <String[]>] [-NoRecursion] [-Server <VIServer[]>] [<CommonParameters>]

Related Commands

Remove-VM
New-VM
Set-VM
Move-VM
Start-VM
Stop-VM
Suspend-VM
Restart-VM

Detailed Description

Retrieves the virtual machines on a vSphere server. Returns a set of virtual machines that correspond to the filter criteria provided by the cmdlet parameters. For virtual machines with multiple NICs and multiple IP addresses, the IPAddress property of the VMGuest object contains all IP addresses of the virtual machine. The IP at position 0 is the primary IP address.

Parameters

NAME DESCRIPTION REQUIRED? PIPELINE INPUT DEFAULT VALUE
Datastore Specify datastores to filter the virtual machines associated with them. Passing values to this parameter through a pipeline is deprecated and will be removed in a future release. false true (ByValue)
Location Specify vSphere container objects (such as folders, datacenters, and clusters) you want to search for virtual machines. false true (ByValue)
Name Specify the names of the virtual machines you want to retrieve. false false
Id Specify the IDs of the virtual machines you want to retrieve. false false
NoRecursion Indicate that you want to disable the recursive behavior of the command. false false
Server One or more vSphere servers to apply the command on. If no value is given to this parameter, the command runs on the server currently specified in the $DefaultVIServer variable. false false

Input Type

Return Type

VMware.VimAutomation.Types.VirtualMachine

Get the VMware tools status and version for all guests

Leave a Reply

Your email address will not be published.