Tag Archives: PowerCLI

The VESI 1.2 – Get it now

People who read my blog know how much I like the Virtualisation EcoShell, I love the way it adds the power of PowerCLI back into the GUI to enable you to create customised GUI’s all of your own enhancing the true power of PowerShell and allowing people who do not know how to code in PowerCLI (yet) the chance to harness the power.

Version 1.2  of the VESI has now been released and it has some great new features:

Continue reading →

PowerCLI: Host Network Config

Whilst on a recent engagement with a customer we were looking at best practices and trying to quickly see how each PortGroup was configured, did all hosts have the same nics assigned to the same vSwitches, were all Portgroups setup the same to use the correct active and standby adapters ?

Have you ever tried doing this from the GUI ? Believe me it will take about 10 minutes to manually copy the relevant information from each host and if you have multiple PortGroups and multiple vSwitches then you can see how long this will take to check against best practice !

I think you know what is coming….

This came up again when someone asked me how to achieve exactly the same thing so I bumped it up my list of scripts I need to write.

Check out the below PowerCLI script, it lists all the needed information to perform this best practice analysis as you can see from the example output:

image

Continue reading →

PowerCLI: More HAL Information

If you have performed Physical to Virtual (P2V) Migrations before you will know about the significance of having the correct Hardware Abstraction Layer (HAL) installed within the operating system.

Without the correct HAL you may experience a speed decrease or even a hung operating system.

For a single processor VM you will need a Uniprocessor Hal and for a multi (2-8) processor VM you will need a Multiprocessor Hal.

The following one-liner expands on my previous one-liner to include the following information:

  • Name
  • Number of CPUs
  • HAL installed in the OS
  • OS Version
  • OS Service Pack Version

Continue reading →

HA Slot Size Information

Do you have HA enabled cluster ? If you do then you will need to know what a slot size is, that’s if you don’t already, if you do already then just cut straight to the cool PowerCLI example….

I’m not going to explain this completely as I could never write such an excellent explanation as Duncan over at Yellow bricks, I highly recommend reading this post as it is pure excellence.

So what is a slot size ?

If you have a HA enabled cluster and have set the admission control to ‘Prevent VMs from being powered on if they violate availability constraints’, this means when your cluster does not have enough room to start VMs if a host fails then you will violate the constraints of the cluster and vCenter will not allow you to power on your next VM, but how does it know when you do not have enough room for another VM to power on ?

Continue reading →

PowerCLI: How many VMs on your Datastores ?

How many VMs do you have on your datastores ?  Do you know ? should you care ?

Yes, you should care, you should care because over saturated datastores can cause issues with IO and also cause scsi locks if you are using fibre.  So what is the sweet spot ?

Unfortunately its one of those “It Depends” situations, isn’t everything !

It depends on the type of shared storage you are using, fibre, iSCSI, NFS and also depends on the types of VMs you are using, all I can recommend is that you try and distribute your VMs evenly and try and think about the type of VMs you are putting on the same datastore, for example, if you have multiple SQL servers on the same datastore or if you have an exchange server on the same datastore as your SQL VM’s then do something out it.

The first place I would start is by reading the great Yellow-Bricks article “Max amount of VMs per VMFS volume” where Duncan tells us how he works out his sweet spot 😉

You can see how evenly you are currently distributed with the following one-liner:

Get-Datastore | Select Name, @{N="NumVM";E={@($_ | Get-VM).Count}} | Sort Name

Example Output:

Name NumVM
ESX01_Local 0
iscsi_0 0
iscsi_1 2
iscsi_2 1
NFS_1 7

And don’t forget, with the wonders of Move-VM and SVMotion we can move some VM’s around to start evenly distributing the load on our datastores.

I would also suggest monitoring from the SAN up so you can see straight way if you have a volume or LUN issue.

PowerCLI: One-Liners Checking Host Network Information

Sometimes as a consultant when performing an initial look or a healthcheck on a new system you will want to confirm all hosts have the correct network information, if there is a mis-configured vmotion portgroup or something similar then this could impact HA or if there is an incorrect DNS server then this may also have issues further down the line with your service console.

The following quick one-liners display some vital information for each host, errors can be seen at a glance, rather than checking each host individually, for us to gain this information we use the wonderful Get-VMHostNetwork cmdlet and expand a few areas of interest:

  • Remember these can be narrowed down further by adding the Get-Cluster “MyCluster” | to the start of the line.
  • Also remember this information can also be exported to a csv by adding | Export-csv “C:\info.csv” to the end of the line.

To list all ESX Hosts and their Service console information: Continue reading →

New PowerCLI Blogger

Anyone who has ever wondered how to do anything in PowerCLI and added a question to the PowerCLI community will know the name LucD or if you are on twitter, LucD22or if you were at VMWorld you will have seen the man in person presenting “TA2650 – Taking PowerCLI to the next level” together with Hal Rottenberg

After much peer pressure and beating with large sticks, Luc has started a blog, if his help on the communities is anything to go by you will know that this blog is surely to be a great place for PowerCLI and PowerShell knowledge in general.

So go over to Luc’s Blog now and add him to your RSS feeder, there are already a couple of nice posts on there explaining some of what happened at VMWorld and I cant wait for the future posts.

Dont forget he has also appeared a couple of times on this blog, giving very complex and informative posts.

Go now, stop reading this !

PowerCLI: APIs made easy “Project Onyx”

For those of you who are living on Mars it is VMworld, No I am not there but I am trying to keep up with all the information coming from VMworld.

One of the coolest things I have seen is “Project Onyx”

Onyx is a cryptocrystalline form of quartz, but apart from that its also a code name for a cool new app the VMware PowerCLI team are working on.

Project Onyx basically allows you to record what you are doing in the virtual infrastructure client and turn it into PowerCLI scripts, so all those things you wanted to script but never knew how can now be achieved.

The PowerCLI team will be giving this new tool to a select few at VMworld to test as it is still in beta, hopefully a wider beta will be released at some point in the future.

For the meantime why don’t you check out the PowerCLI Blog for more information here (Love the paperclip reference)

Continue reading →

PowerCLI: Mass provision datastore’s

At the moment I am adding around 50 datastore’s to a host, now whilst I love using the great Virtual Infrastructure Client wizard to do this after adding two of the 50 i remembered what someone said (can’t remember who)….. If you do something more than once, script it.

So guess what I did….

The following script was used to add the datastore’s from a csv file whilst I happily worked on other things.

The csv file consisted of the following:

LUNid,Hostid
101,1
221,2
331,3
451,4
521,5
661,6

etc etc, the naming convention for my datastores is SAN_HOSThostid_LUNlunid so this was easily scripted as so:

$CSVFile = "C:\Temp\Datastores.csv"
$MYESXHost = "ESX01.virtu-al.local"
$VMHBA = "vmhba2:0:"

Connect-VIServer MYVISERVER
$CSV = Import-CSV $CSVFile
$ESXHost = Get-VMHost $MYESXHost
$ESXHost |Get-VMHostStorage -RescanAllHBA
Foreach ($Item in $CSV){
  
$HostID = $Item.HostId
  
$LunID = $Item.LunID
  
Write "Creating SAN_HOST$($HostID)_LUN$($LunID)…"
  
$ESXHost |New-Datastore -Vmfs -Name "SAN_HOST$($HostID)_LUN$($LunID)" -Path "$($VMHBA)$($HostID)"
}

The New-Datastore cmdlet also has a -BlockSizeMB parameter which can be used to specify the block size of VMFS in megabytes.

All in all it took me around 10 minutes to add 50 datastore’s which I think would have taken significantly longer through the GUI.  Yet another reason to start learning PowerCLI !

PowerCLI: One-liners last 10 VMs created and removed

I was asked if it was easy enough to get a list of the last 10 VMs created in a virtual Infrastructure, the answer is yes, its a one-liner !

To list the last 10 VMs created, cloned or imported use the following:

Get-VIEvent -maxsamples 10000 |where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage -First 10

 

Or if you would like to get the last 5 VMs removed from your VI use the following:

Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name -eq "VmRemovedEvent"} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 19

As requested, here is how you can get a list of the VM’s created over the last 14 days:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) | where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage

And a list of the VMs removed over the last 14 days:

Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(–14) |where {$_.Gettype().Name-eq "VmRemovedEvent"} |Sort CreatedTime -Descending |Select CreatedTime, UserName,FullformattedMessage