VMwareVSphereAndvSAN Module | Vmware PowerCLI Reference

Getting Started with VMware vSphere And vSAN cmdlets

Provides cmdlets for automated administration of the vSphere environment.

Step 1: Connect to Environment

To setup a connection you should use the Connect-ViServer command. Run the code sample below to connect.

# Connects to a vCenter system by using the User and Password parameters.

Connect-VIServer -Server 10.23.112.235 -Protocol https -User admin -Password pass

You can also connect to remote environment by running one of the alternative options to connect below:

Option 1 :

# Connects to a vCenter system by using a credential object.

Connect-VIServer Server -Credential $myCredentialsObject -Port 1234

Option 2 :

# Connects by using integrated authentication. In this case, the credentials you are logged on to your machine must be the same as those for the server.

Connect-VIServer Server

Option 3 :

# Connects to a server and save the credentials in the credential store. After the credentials are stored, you can connect to the server without specifying them. To get a previously saved credential store item, use the Get-VICredentialStoreItem cmdlet.

Connect-VIServer "Server" -User user -Password pass -SaveCredentials

Option 4 :

# Connects to a server by choosing the server address from a list of previously connected servers.

Connect-VIServer -Menu

Option 5 :

# Connects to a vCenter system which is a part of a federation vCenter system. This will connect you to all vCenter systems in the federation as well.

Connect-VIServer "Server" -AllLinked

Option 6 :

# Connects to a vCenter system that runs in a VMware managed cloud using an API token from the VMware Cloud Services portal.

$oauthCtx = New-VcsOAuthSecurityContext -ApiToken "a3f35067-80b5-44f0-a0bc-e19f2bc17fb7" $samlCtx = New-VISamlSecurityContext -VCenterServer "Server" -OAuthSecurityContext $oauthCtx Connect-VIServer -Server "Server" -SamlSecurityContext $samlCtx

Option 7 :

# Connects to a vCenter system which is federated with VCF SSO.

$oauthCtx = New-VcfOAuthSecurityContext "Server" -ApiToken "a3f35067-80b5-44f0-a0bc-e19f2bc17fb7" Connect-VIServer -Server "Server" -VcfOAuthSecurityContext $oauthCtx

Option 8 :

# Connects to a vCenter system which is federated with VCF SSO.

Connect-VIServer -Server "Server" -VcfApiToken "a3f35067-80b5-44f0-a0bc-e19f2bc17fb7"

Step 2: Retrieve a object by running a Get command

You can READ objects by using Get-VMHost cmdlet. See example below:

# Retrieves all hosts in the specified datacenter.

Get-VMHost -Location MyDatacenter