Archive for July, 2009

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 ?

More >

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

PowerShell Toolbar

If you are a fan of Powershell and PowerCLI then you have to check this out, Shay Levy has updated his PowerShell toolbar which has been around for a while now and added some new sections.

The Powershell toolbar is a toolbar (downloadable here) which gives you all the powershell links and resources you will ever need.

More >

Running a PowerCLI Scheduled task

There are a fair few PowerCLI scripts which can be run as scheduled tasks, some that email you or maybe a monitoring script but recently I have been asked how this can be done, what do you put in the Run line for the script to work properly.

There are two ways of doing this really:

1.  Add a line to a start of each of your scripts to make sure it loads the PowerCLI snapin, without which PowerShell will not recognise any of the PowerCLI cmdlets.

More >

PowerCLI: Host Hardware One-Liner

A quick one-liner which gives you an outline of your Host hardware information:

Get-VMHost |Sort Name |Get-View |
Select Name,
@{N
=Type;E={$_.Hardware.SystemInfo.Vendor+ + $_.Hardware.SystemInfo.Model}},
@{N
=CPU;E={PROC: + $_.Hardware.CpuInfo.NumCpuPackages + CORES: + $_.Hardware.CpuInfo.NumCpuCores + MHZ: + [math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}},
@{N
=MEM;E={“” + [math]::round($_.Hardware.MemorySize / 1GB, 0) + GB}} | Export-Csv c:\hostinfo.csv

Output Example:

Name Type CPU MEM
prod01.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2993 32 GB
prod02.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2993 32 GB
prod03.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2993 32 GB
prod04.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 4 MHZ: 2993 16 GB
tst10.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2660 16 GB
tst11.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2660 16 GB
tst12.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2660 16 GB
tst13.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2992 32 GB
tst14.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2992 32 GB
tst15.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2992 32 GB
tst16.domain.local Dell Inc. PowerEdge 2950 PROC: 2 CORES: 8 MHZ: 2992 32 GB

PowerCLI: More One-Liner Power

A few one-liners inspired by the people who I follow on twitter, firstly Jason Boche was working on a script to reset CPU and Memory limits to “Unlimited” for all VMs in vCenter, I joked with him that this was a one liner, firstly we can set the memory limits with the following:

Get-VM | Get-VMResourceConfiguration | Where-Object {$_.MemLimitMB -ne -1} | Set-VMResourceConfiguration -MemLimitMB $null

The –1 equates to an “Unlimited” setting.  This doesn’t address the CPU limits, this can be done using the following:

Get-VM | Get-VMResourceConfiguration | Where-Object {$_.CpuLimitMhz -ne -1} | Set-VMResourceConfiguration -CPULimitMhz $null

More >

PowerCLI: Stats One-liner

Ever wondered how your VM’s are doing ?  What resources are they using, do they have too many CPU’s or too much memory ?

This simple one-liner will give you a list of each of your vms, it will tell you how many cpu’s, the amount of memory, average cpu usage for x amount of days and the average memory usage for x amount of days, how cool is that ?!

Get-VM |Where {$_.PowerState -eq "PoweredOn"} |
Select Name,Host,NumCpu,MemoryMB, @{N="Cpu.UsageMhz.Average";E={[Math]::Round((($_ |Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddHours(-24)-IntervalMins 5 -MaxSamples (12) |Measure-Object Value -Average).Average),2)}}, @{N="Mem.Usage.Average";E={[Math]::Round((($_ |Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-24)-IntervalMins 5 -MaxSamples (12) |Measure-Object Value -Average).Average),2)}} |Export-Csv c:\Temp\stats.csv

Update 03 July 2009: This has been updated as it was not collecting the average over the given timescales, the original code was selecting 1 sample from the timeframe.

More >