Posts

Showing posts from March, 2017

Powercli : One-liners

Over the last few months I started learning Powercli and wrote different PowerCLI One-liners while working. I will add more in the list later on by updating this post. -           Get all VM names with powerstat in a cluster and export result to a csv :- Get-Cluster mycluster| Get-VM | select Name, PowerState |Export-CSV 'C:\Users\aj\Desktop\test.csv' -           Get a list of all VMs in a cluster and the datastore in which the VMs resides Get-Cluster | Get-VM | select name, @{N="Datastore";E={Get-Datastore -VM $_}} | sort name -           Get poweron VM names :- Get-VM | select name,powerstate | ?{$_.powerstat -match "PowerON"} -           Get vmware tools status :- Get-vm |% { get-view $_.id } | select Name, @{ Name=”Tools Status”; Expression={$_.guest.toolsstatus}}, @{ Name=”Tools Runnin...

Powercli : Connecting and disconnecting servers

Image
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...

Introduction to PowerCLI

Image
Have you ever had to create 100 virtual machines in a really short period of time, change a setting on all of your hosts, or make an advanced report for your boss to show how full the hard disks of your virtual machines are? If you have, you know that performing these tasks using the vSphere client will take a lot of time. This is where automation can make your job easier.  VMware vSphere PowerCLI  is a powerful  tool that can perform these tasks and much more. And the best thing is that it is free! VMware vSphere PowerCLI is a  command-line interface  distributed as a Microsoft Windows PowerShell snap-in. You can use PowerCLI to automate your vSphere hosts, virtual machines, virtual networks, storage, clusters, vCenter Servers, and more. Downloading and installing PowerCLI Before you can install PowerCLI, you have to download the PowerCLI installer from the VMware website. You will need a My VMware account to do this. Downloading PowerCLI ...