Powercli : Connecting and disconnecting servers
After installation of powercli on desktop now its time to start using it , for that you have to connect to a vCenter server or ESXi server.
Connecting to a server
If you are not connected to a vCenter or an ESXi server, you will get an error message if you try to run a PowerCLI cmdlet. Let's try to retrieve a list of all of your datacenters using the following command:
PowerCLI C:\> Get-Datacenter
The output of the preceding command is as follows:
Get-Datacenter : 03/27/2017 12:37:36 PM Get-Datacenter Youare not currently connected to any servers. Please connect firstusing a Connect cmdlet. At line:1 char:1 + Get-Datacenter + ~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (:) [Get-Datacenter], ViServerConnectionException + FullyQualifiedErrorId :Core_BaseCmdlet_NotConnectedError,VMware.VimAutomation.ViCore.Cmdlets.Com
You see that this gives an error message. You first have to connect to a vCenter Server or an ESXi server using the Connect-VIServer
cmdlet. If you have a vCenter Server, you only need to connect to the vCenter Server and not to the individual ESXi servers. It is possible to connect to multiple vCenter Servers or ESXi servers at once. The Connect-VIServer
cmdlet has the following syntax:
Connect-VIServer [-Server] <String[]> [-Port <Int32>] [-Protocol <String>] [-Credential <PSCredential>] [-User <String>] [-Password <String>] [-Session <String>] [-NotDefault] [-SaveCredentials] [-AllLinked] [-Force] [<CommonParameters>]
Connect-VIServer -Menu [<CommonParameters>]
As you can see, the Connect-VIserver
cmdlet has two parameter sets: Default
and Menu
. In the Default
parameter set, the –Server
parameter is required. In the Menu
parameter set, the –Menu
parameter is required. You cannot combine parameters from the Default
parameter set with the Menu
parameter set.
Let's first try to connect to a vCenter Server with the following cmdlet:
PowerCLI C:\> Connect-VIServer –Server 192.168.0.132
192.168.0.133
is the IP address of the vCenter Server in my home lab. Replace this IP address with the IP address or DNS name of your vCenter or ESXi server.
The preceding command will pop up a window in which you have to specify server credentials to connect to your server if your Windows session credentials don't have rights on your server. Enter values for User name and Password and click on OK.
If you specified valid credentials, you will get output similar to the following:
Name Port User
---- ---- ----
192.168.0.132 443 root
You can also specify a username and password on the command line as follows:
PowerCLI C:\> Connect-VIServer –Server 192.168.0.132 -User admin -Password pass
You can also save the credentials in a variable with the following command:
PowerCLI C:\> $Credential = Get-Credential
You can now use the $Credential
variable to connect to a server using the –Credential
parameter, as follows:
PowerCLI C:\> Connect-VIServer –Server 192.168.0.132 –Credential$Credential.
Courtesy/Ref :- Learning PowerCLI by Robert van den Nieuwendijk
Comments
Post a Comment