Hello,
I am about to start learning PowerCli for admisitrative purpose, I have Powershell 3.0 and PowerCli installed on my machine (Win 7), in powershell I have assigned execution policy as 'remotesingned' and added the snap in 'Add-PSSnapin VMware.VimAutomation.Core'. When I try to launch powercli, a CMD (like) windows pops up and vanishes the screen in seconds, no luck on launching powercli with administrator. The bainry used for installation is 'VMware-PowerCLI-5.1.0-793510.exe'
Could you please assit me setting the powercli console.
Regards,
Demee1988
Strange, PowerCLI 5.1, although not officially supported in PowerShell v3, should work.
To recap, you have opened a PowerShell prompt and then did the Add-PSSnapin, correct ?
From that PowerShell prompt can you check if the PowerCLI snapin was loaded ? Do
Get-PSSnapin -Name VMware.VimAutomation.Core
Do you get anything back on screen ?
If yes, check if you can see the PowerCLI cmdlets. Do a
Get-Command -Module VMware.VimAutomation.Core
If you see a whole bunch of cmdlets passing, try to connect to a vCenter or an ESXi host with
Connect-VIServer YourVCHostname
Does that work (you might have to use an account and password with the User and Password parameters)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I followed your steps and it worked well , but on opening powercli it flashes away
Regards,
deeme1988
Try starting PowerShell in v2 mode.
In the Run option type
powershell.exe -version 2
Now from the PowerShell prompt load the PowerCLI snapin and connect to the vCenter.
Does that work ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I tried running powercli cmdlets on powershell 2 and the results in below.
PS C:\Users\deemee1988> powershell.exe -version 2Windows PowerShellCopyright (C) 2009 Microsoft Corporation. All rights reserved.PS C:\Users\deemee1988> powerclipowercli : The term 'powercli' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:9+ powercli <<<<+ CategoryInfo : ObjectNotFound: (powercli:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundExceptionPS C:\Users\deemee1988> Connect-viserverConnect-viserver : The term 'Connect-viserver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:17+ Connect-viserver <<<<+ CategoryInfo : ObjectNotFound: (Connect-viserver:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundExceptionPS C:\Users\deemee1988> Connect-viserver 192.168.190.3Connect-viserver : The term 'Connect-viserver' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:17+ Connect-viserver <<<< 192.168.190.3+ CategoryInfo : ObjectNotFound: (Connect-viserver:String) [], CommandNotFoundException+ FullyQualifiedErrorId : CommandNotFoundExceptionPS C:\Users\deemee1988>
But I had luck with errors on running it over Powershell 3
PS C:\Users\deemee1988> Connect-VIServer 192.168.190.3 WARNING: There were one or more problems with the server certificate: * A certification chain processed correctly, but terminated in a root certificate which isn't trusted by the trust provider. * The certificate's CN name does not match the passed value. Certificate: [Subject] E=support@vmware.com, CN=VC.mytestlab.com, OU="VMware, Inc.", O="VMware, Inc." [Issuer] E=support@vmware.com, CN=VC.mytestlab.com, OU="VMware, Inc.", O="VMware, Inc." [Serial Number] EEF00DE5 [Not Before] 12/18/2012 7:03:20 PM [Not After] 12/16/2022 7:03:20 PM [Thumbprint] 4F2CBD6DEC902B7C4DB90614AF9BD192AC86ED61 The server certificate is not valid. WARNING: THE DEFAULT BEHAVIOR UPON INVALID SERVER CERTIFICATE WILL CHANGE IN A FUTURE RELEASE. To ensure scripts are not affected by the change, use Set-PowerCLIConfiguration to set a value for the InvalidCertificateAction option. Working with multiple default servers? Select [Y] if you want to work with more than one default servers. In this case, 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. 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. Select [N] if you want to work with a single default server. In this case, when you run a cmdlet and the target servers cannot be determined from the specified parameters, the cmdlet runs against the last connected server. WARNING: WORKING WITH MULTIPLE DEFAULT SERVERS WILL BE ENABLED BY DEFAULT IN A FUTURE RELEASE. You can explicitly set your own preference at any time by using the DefaultServerMode parameter of Set-PowerCLIConfiguration. [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y Name Port User ---- ---- ---- 192.168.190.3 443 mytestlab\vcadmin PS C:\Users\deemee1988> get-vm get-vm : 12/21/2012 8:06:32 PM Get-VM Server localhost is not connected. At line:1 char:1 + get-vm + ~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-VM], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetVM Name PowerState Num CPUs MemoryGB ---- ---------- -------- -------- Test PoweredOff 1 0.250 PS C:\Users\deemee1988> Get-Datacenter Get-Datacenter : 12/21/2012 8:33:35 PM Get-Datacenter Server localhost is not connected. At line:1 char:1 + Get-Datacenter + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Datacenter], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetDatacenter Name ---- MyTestLab PS C:\Users\deemee1988> Get-EsxTop Get-EsxTop : 12/21/2012 8:33:53 PM Get-EsxTop Server localhost is not connected. At line:1 char:1 + Get-EsxTop + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-EsxTop], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetEsxTop PS C:\Users\deemee1988> Get-NetworkAdapter Get-NetworkAdapter : 12/21/2012 8:34:08 PM Get-NetworkAdapter Please specify at least one of the following: VirtualMachine, Template or Snapshot. At line:1 char:1 + Get-NetworkAdapter + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-NetworkAdapter], ViError + FullyQualifiedErrorId : Core_VirtualDeviceGetter_GetMoListFromCmdletParameter_InsufficientParameters,VMware.VimA utomation.ViCore.Cmdlets.Commands.VirtualDevice.GetNetworkAdapter PS C:\Users\deemee1988> Connect-VIServer 192.168.190.3 Name Port User ---- ---- ---- 192.168.190.3 443 mytestlab\vcadmin PS C:\Users\deemee1988> Get-EsxTop Get-EsxTop : 12/21/2012 8:35:21 PM Get-EsxTop Server localhost is not connected. At line:1 char:1 + Get-EsxTop + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-EsxTop], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetEsxTop PS C:\Users\deemee1988> Get-Task Get-Task : 12/21/2012 8:35:41 PM Get-Task Server localhost is not connected. At line:1 char:1 + Get-Task + ~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-Task], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetTask PS C:\Users\deemee1988> Get-VMGuestNetworkInterface Get-VMGuestNetworkInterface : 12/21/2012 8:35:51 PM Get-VMGuestNetworkInterface You must specify at least one of the VM and VMGuest parameters. At line:1 char:1 + Get-VMGuestNetworkInterface + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-VMGuestNetworkInterface], VimException + FullyQualifiedErrorId : Core_GetVmGuestInfoBaseCmdlet_ValidateParameters_MandatoryParameters,VMware.VimAutomatio n.ViCore.Cmdlets.Commands.GetVmGuestNetworkInterface PS C:\Users\deemee1988> Get-VMHost Get-VMHost : 12/21/2012 8:36:09 PM Get-VMHost Server localhost is not connected. At line:1 char:1 + Get-VMHost + ~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-VMHost], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.GetVMHost Name ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version ---- --------------- ---------- ------ ----------- ----------- ------------- ------------- ------- esxi5-1.mytestlab... Connected PoweredOn 2 74 5382 0.906 2.000 5.0.0 esxi5-2.mytestlab... Connected PoweredOn 2 119 5382 0.909 2.000 5.0.0 PS C:\Users\deemee1988> Get-VMHostAccount Get-VMHostAccount : 12/21/2012 8:36:23 PM Get-VMHostAccount Server localhost is not connected. At line:1 char:1 + Get-VMHostAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-VMHostAccount], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.Host.GetVMHostAccount Get-VMHostAccount : 12/21/2012 8:36:23 PM Get-VMHostAccount The requested operation is only supported when connected directly to ESX host. At line:1 char:1 + Get-VMHostAccount + ~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Get-VMHostAccount], VimException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryValidateEsxConnection_ConnectedToVC,VMware.VimAutoma tion.ViCore.Cmdlets.Commands.Host.GetVMHostAccount PS C:\Users\deemee1988> Get-VMHostDisk Get-VMHostDisk : 12/21/2012 8:36:36 PM Get-VMHostDisk Server localhost is not connected. At line:1 char:1 + Get-VMHostDisk + ~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Get-VMHostDisk], ViServerConnectionException + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_TryVerifyIsConnected_NotConnected,VMware.VimAutomation. ViCore.Cmdlets.Commands.Host.Storage.GetVMHostDisk DeviceName TotalSectors ---------- ------------ /vmfs/devices/disks/mpx.vmhba1:C0:T0:L0 83886080 /vmfs/devices/disks/mpx.vmhba1:C0:T0:L0 83886080 PS C:\Users\deemee1988>
Regards,
deemee1988
In that first session, you should load the PowerCLI snapin first.
Like this
Add-PSSnapin -Name VMware.VimAutomation.Core
Then you can continue with the Connect-VIServer.
In that 2nd session you seem to have started the PowerCLI prompt (PowerShell and the PowerCLI loaded) from the PowerCLI Start menu or desktop.
In that session it looks as if you have a problem
Is 192.168.190.3 the vCenter server ?
Are you running the PowerCLI session on that server ?
It looks as if the PowerCLI cmdlets can't connect to the server "localhost", could it be that ports 442 and 902 are not opened ?
Do you have a firewall running on the vCenter server ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Over here Localhost is Win 7 clinet, my VC runs over ip 192.168.190.3, now powershell is clean without error.
PS C:\Users\deemee1988> Connect-viserver 192.168.190.3Name Port User---- ---- ----192.168.190.3 443 mytestlab\vcadminPS C:\Users\deemee1988> get-vmName PowerState Num CPUs MemoryGB---- ---------- -------- --------Test PoweredOff 1 0.250PS C:\Users\deemee1988> Get-DatacenterName----MyTestLabPS C:\Users\deemee1988> Get-HAPrimaryVMHostName ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz MemoryUsageGB MemoryTotalGB Version---- --------------- ---------- ------ ----------- ----------- ------------- ------------- -------esxi5-2.mytestlab... Connected PoweredOn 2 70 5382 0.911 2.000 5.0.0PS C:\Users\deemee1988>
Loading powercli snapin on powershell 2 works well with cmdlets, but any solution for loading powercli and thank you for provinding a work around
Regards,
deemee1988
So, is your problem solved, or are there still problems ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference