PowerCLI: Number of vCPUs in a cluster

Inspired by Jason Boche’s article: http://www.boche.net/blog/index.php/2009/08/18/hidden-virtual-cpu-limit-restriction-in-esx-3-5/ and also William Lam’s Perl Script (http://communities.vmware.com/docs/DOC-10556).  I decided to re-create this in PowerCLI.

If you haven’t seen William’s scripts, I strongly suggest you check out the Perl Sample code where he stores them here: http://communities.vmware.com/community/developer/codecentral/vsphere_perl, he has been coding mad recently and turning out some really good stuff.

The PowerCLI script gives the following output:

Cluster: Production
Host: vmgesx01.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 4
Host: vmgesx02.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 3
Host: vmgesx03.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 2
Host: vmgesx04.vmguru.com
Misc.RunningVCpuLimit: 128
Number of vCPU on host: 5
———-
Number of vCPU in Production: 14
———-

Continue reading

PowerCLI: Daily Report V2

Firstly I would like to thank everyone who took the time to comment on my previous Daily Report script, I really appreciate the feedback and have never had so many comments !

Now onto V2…

This one will take a while longer to run than the last script but as its a scheduled task we are not really worried about that, we are hardly going to sit there and watch it running !

I think you will agree the results are worth the wait:

What’s new

  • Bug Fixes
  • Active VMs count
  • Inactive VMs count
  • DRS Migrations count and list
  • Correct NTP Server check for each host
  • VMs stored on local datastores
  • NTP Service check for each host
  • vmkernel warning messages for each host
  • VM CPU ready over x%
Continue reading

PowerCLI: Reading host log files

Recently I needed to check the vmkernel log file on a host for any errors relating to a disk issue I was having, I did this in the normal way of using putty to get to my server and then a cat /var/log/vmkernel.  That is one way of doing it but did you know you could also do this through PowerCLI and add some automation into it ?  Well you can….

There is a cmdlet called Get-Logtype, if we connect to a VirtualCenter and then run this you will see the following:

Get-LogType

image

Continue reading

PowerCLI: Processor Types

Ever wanted to check the hosts in your vCenter to make sure they are all the same type, you can use the following one liner to do this:

Get-VMHost | Sort Name | Get-View | Select Name, @{N=CPU;E={$_.Hardware.CpuPkg[0].Description}} | Export-Csv c:\cpuinfo.csv

Sample Output:

Name CPU
tesesx01.mydomain.com Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
tesesx02.mydomain.com Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
tesesx03.mydomain.com Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx04.mydomain.com Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx05.mydomain.com Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx06.mydomain.com Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx07.mydomain.com Intel(R) Xeon(R) CPU E5450 @ 3.00GHz

Or if you want to add the cluster name in there as well:

Get-VMHost | Sort Name | Get-View | Select Name, @{N=Cluster;E={Get-Cluster -VMHost (Get-VMHost $_.Name)}},@{N=CPU;E={$_.Hardware.CpuPkg[0].Description}} | Export-Csv c:\cpuinfo.csv

Sample Output:

Name Cluster CPU
tesesx01.mydomain.com Test Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
tesesx02.mydomain.com Test Intel(R) Xeon(R) CPU 5160 @ 3.00GHz
tesesx03.mydomain.com Production Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx04.mydomain.com Production Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx05.mydomain.com Production Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx06.mydomain.com Production Intel(R) Xeon(R) CPU E5450 @ 3.00GHz
tesesx07.mydomain.com Production Intel(R) Xeon(R) CPU E5450 @ 3.00GHz

vSphere 4.0 Quickstart Guide

book

For a while now I have been writing a book with a number of other people from the VMware community:

This book has been designed to be an affordable pocket size book, ideal for quick tips and how-to’s and of course it is full with PowerCLI examples for each of the tasks showing how PowerCLI is useful in every area of the virtual infrastructure.

The book is not available at the moment, we are still adding some final touches but please keep an eye out on my blog or if you are at VMWorld later this month you should be able to grab a copy.

For more information about this book check out Duncan’s blog post here

PowerCLI: Do you have the time ?

Sorry for the lack of updates recently, I have been on vacation.  I thought I would ease myself back in with a quick one-liner.

We had an issue on one of our esx hosts today and when I went to check the logs I noticed the time was out, on further checking the server the NTP service had stopped.

I wrote a quick one liner to double check all our Hosts were using the same NTP Server and that the service was started:

Get-VMHost |Sort Name|Select Name, @{N=NTPServer;E={$_ |Get-VMHostNtpServer}}, @{N=ServiceRunning;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq ntpd}).Running}}

This will give you a nice table letting you know the state of your hosts time, if you do happen to have a host with an incorrect NTP server then you can set it like this:

Add-VMHostNtpServer -VMHost MYHost -NtpServer ntp.mydomain.com

Or if one of the services has stopped you can start it again with the following:

Get-VmHostService -VMHost MyHost | Where-Object {$_.key -eq ntpd} | Start-VMHostService

Example output from my one-liner:

Name NTPServer ServiceRunning
testesx01.mydomain.com ntp.mydomain.com TRUE
testesx02.mydomain.com ntp.mydomain.com FALSE

PowerCLI: Daily Report

This script will save you time and resources.

I have been using this script for the past month and it has highlighted a number of issues which would have been harder to find without it.

Daily Report does what it says on the tin, it runs as a scheduled task before you get into the office to present you with key information about your infrastructure in a nice easily readable format.

This script picks on the key areas of the virtual infrastructure and reports it all in one place so all you do in the morning is check your email.

One of they key things about this report is if there is no issue in a particular place you will not receive that section in the email, for example if there are no datastores with less than 5% free space (configurable) then the disk space section will not show in the email, this ensures that you have only the information you need in front of you when you get into the office.

So what areas does this script report on ?

Continue reading

PowerCLI: Local stored VM’s One-Liner

So, you have installed ESX on your nice pair of RAID 1 72GB or 146GB disks and have a whole bunch of disk space left over, what do you do with it, well if your anything like me you will format it as a VMFS partition and use it for storing Templates or temporary VMs that you dont care if they die.

But what if your not like me, what if your one of those admins who doesnt really know where they are storing their VM’s, they dont even care, they just click to order the storage by free space and put it on the one that has the most free space – even if it is local storage (come on, we all know them).

The following one-liner will list all the VMDK files for VMs stored on your local storage.

Please note:  The where clause assumes your local storage has the word local in it, this can obviously be changed or you can use a –nomatch to exclude your san storage if needs be.

Get-Datastore |where {$_.Name -match local} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\LocalVMs.csv

You can also add multiple names for your local storage by added them with a | between them in the match string (Thanks LucD) like the following:

Get-Datastore |where {$_.Name -match store|local|storage} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\LocalVMs.csv