Archive for the ‘Powershell’ Category

Thinking, Building and Scripting Globally – a London VMUG presentation.

July 14th, 2011 4 comments

I have the privilege today of presenting at the London VMware User Group.

My presentation is split into two parts, first of all looking at why setting standards, creating processes and adding automation is now more important than ever as we work towards building an infrastructure for cloud computing.

I go through how “cloud thinking” is not just about the cloud being used to solve an IT problem but rather the cloud being a busines transformation to increase your business flexibility.

Your ESX(i) host build is the foundation of that cloud.

Then I head into the technical details of how to create a single PowerCLI script to build ESX or ESXi anywhere in your organisation. Using PowerCLI removes the dependency on any Service Console scripting so you can move towards an ESXi only infrastructure as that is the only hypervisor option for vSphere 5.

Having a single global script allows you to set standards and gives you way to reduce complexity & errors.

Read more…

Installing HP Agents on ESX with PowerCLI and Putty/Plink

March 7th, 2011 4 comments

Anyone who needs to build multiple ESX(i) hosts naturally looks to scripting to automate the process. Scripting allows for faster deployment once you have developed the script but equally important reduces human error. It’s far to easy to mistype a port group name, vlan number or IP address. Scripting removes this element of humen error and allows you to build ESX(i) hosts preditably and quickly.

Unfortunately there are just some things that PowerCLI cannot natively automate such as installing HP agents on ESX as this requires console / SSH access to the ESX host and running the install “locally”.

Hopefully hardware vendors will see the benefits of integration with VMware Update Manager and allow hardware monitoring agents to be installed and updated with Update Manager but until then we have to make another plan.

It is always painful to have developed a fantastic PowerCLI script to automate your build and at the end still have to manually SSH into your ESX host to install a hardware agent.

Read more…

Scripting Flex-10 ESX design with PowerCLI

February 18th, 2011 No comments

My Flex-10 ESX design with simplicity and scalability posts detail the configuration steps required to deploy ESX with Flex-10. There’s a lot of clicking around in the vSphere client that can be automated with PowerCLI.

The steps below will set up the ESX networking component as described in the design posts so can be incorporated into the rest of your PowerCLI build process.

Read more…

NetApp DataONTAP 1.3 released

February 8th, 2011 No comments

NetApp’s Powershell Toolkit has been updated to 1.3.

Highlights are:

  • Create a PSDrive and access the ONTAP file system as if it was a local disk
  • Using a Credential Cache
  • Being able to invoke SSH directly from within DataOntap so you can run any CLI command as the API doesn’t cover everything
  • More -WhatIf parameter usage

You can get more information from Making The Most Of Data ONTAP PowerShell Toolkit 1.3

Microsoft has created a fantastic administration environment with Powershell, the more companies that create PowerShell modules the better so good work NetApp, looking forward to some more!

Categories: NetApp, Powershell Tags: ,

Getting Nic firmware versions with PowerCLI

January 27th, 2011 4 comments

Sometimes you need to delve into the innards of ESX to get information out that just isn’t available through the VMware SDK and so not directly available to PowerCLI.

If you’ve been doing any work recently with HP Flex-10 and its firmware requirements, you may need to find out the network card firmware version which is only available from within the ESX console by typing ethtool -i vmnic0

So, PowerCLI to the rescue, but actually using PowerCLI to call Plink.exe which is Putty’s command-line connection tool. You can use this same process to pull anything that you can get from the ESX console as long as you can parse the results of the command and find the information you need.

Read more…

Updating Broadcom bnx2x Nic Drivers with PowerCLI

November 15th, 2010 4 comments

Now that a new bnx2x driver has been released as detailed in my previous post you will obviously need to deploy it and add it as part of your hopefully scripted build.

I wish VMware Update Manager would be able to apply these driver updates so we can have a single depoyment mechanism but this doesn’t seem to be the case yet.  We live in hope!

So, without Update Manager, I always prefer PowerCLI rather than esxupdate for these kinds of deployments as it fits nicely into a PowerCLI scripted build, you don’t have to have SSH access to install and you can also roll it out easily to multiple ESX hosts.

Read more…

Output Powershell console to a file using Transcript

September 22nd, 2010 1 comment

Sometimes it’s the simple things that really make a difference.

Often when writing any script you have to decide whether to output stuff to the screen or to a file.

What if you need to do both?

Normally you create additional scripting lines or a function to output the response from a cmdlet to a log file which you can review later.

Well I stumbled by accident across a very simple way to avoid this…just use the cmdlets Start-Transcript and Stop-Transcript which will output anything written to the screen into a text file.

$TranscriptFile = "c:\myoutput.log"
Start-Transcript -Path $TranscriptFile

Write-Host "I'm Transcripting!"

Connect-VIServer myvcserver


Invoke-Item $TranscriptFile
Categories: Powershell Tags: ,

Snapshot information from PowerCLI

September 6th, 2010 1 comment

Here are some PowerCLI single line scripts for getting different snapshot information:

Display VM Name and Snapshot Name

Get-VM | Get-Snapshot | select @{name="VM Name"; Expression={$}},name

Display VM Name, PowerState, Host and Snapshot Name

Get-VM | Get-Snapshot | select @{name="VM Name"; Expression={$}},@{name="Power State"; Expression={$_.vm.Powerstate}},@{name="Host"; Expression={$_.vm.Host}},name

Display VM Name and Number of Snapshots

Get-VM | Where{(Get-SnapShot -VM $_ | Measure-Object).Count -gt 0} | Format-Table Name, @{Label="NumSnapshots";Expression={(Get-Snapshot -VM $_ | Measure-Object).Count}}

All snapshots older than a particular date, say 30 days?

Get-VM | Get-Snapshot | Where { $_.Created -lt (Get-Date).AddDays(-0)} | select @{name="VM Name"; Expression={$}},@{name="Power State"; Expression={$_.vm.Powerstate}},name, Created

Datastore and storage information from PowerCLI

September 3rd, 2010 No comments

Here are some PowerCLI single line scripts for getting some storage and datastore information:
Find the Number of VMs on all Datastores

Get-Datastore | Sort-Object Name | Get-View | Format-Table @{Label="Datastore Name";Expression={$_.Info.Name}}, @{Label="Number of VMs";Expression={$_.VM.Length}}

Get VM Guest Disk Free Information

Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}}

Get the 10 VM Guest disks with the least amount of free space

Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskFreeMB";E={[math]::Round((($_.FreeSpace)/1MB),2)}} | Sort DiskFreeMB | Select -First 10

Get combined size of each VMs Disks

Get-VM | select Name, @{ Name="Disks"; Expression={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}

sorted by size

Get-VM | select Name, @{ Name="Disks"; Expression={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }} | sort Disks -descending

Get Disk Path, Capacity, Free and Used space

Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VMName -ExpandProperty Disks | Select VMName, Path, @{Name="DiskCapacityGB";Expression={[math]::Round((($_.Capacity)/1GB),2)}},@{Name="DiskUsedMB";Expression={[math]::Round((($_.Capacity - $_.FreeSpace)/1MB),2)}},@{Name="DiskFreeMB";Expression={[math]::Round((($_.FreeSpace)/1MB),2)}}

Disk timeout settings in registry for VMs using PowerCLI

September 1st, 2010 3 comments

One of NetApp’s best practices is to increase the disk timeout settings for VMs to 190 seconds so VMs don’t blue screen if they temporary lose connectivity to their disks say during a cluster failover.

This is done by amending the Disk Timeout registry value:
HKLM\SYSTEM\CurrentControlSet\Services\Disk\TimeoutValue to DWord 190.

I’m sure you’d love to go through all your VMs and load regedit manually so why not grab a list of VMs using PowerCLI and set the registry value.

The VMs will obviously need to be powered on and you will need permissions to be able to write to the registry.

The procedure is a 2 step process:

The first is to get all the VMs you want to change.
You can use any Get-VM statement you want:

All VMs in a particular Resource Pool

$VMs = Get-VM -Location (Get-ResourcePool "Resource_Pool_Prod") | Where { $_.PowerState -eq "PoweredOn" }


$VMs = Get-ResourcePool "Resource_Pool_Prod" | Get-VM | Where { $_.PowerState -eq "PoweredOn" }

All VMs in a particular Cluster

$VMs = Get-Cluster "LON_PROD1" | Get-VM | Where { $_.PowerState -eq "PoweredOn" }

All VM names starting with WEBSERVER

$VMs = Get-VM "WEBSERVER*" | Where { $_.PowerState -eq "PoweredOn" }

The second stage is to work some registry magic for the VMs you have.

You can then read the current registry value:

ForEach ($VM in $VMs) {
	$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM.Guest.Hostname)
	Write-Host "Registry Value for: "$VM.Guest.Hostname ": " $reg.OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk\").GetValue("TimeoutValue")

To write the registry value:

ForEach ($VM in $VMs) {
	Write-Host "Setting Registry Value for: "$VM.Guest.Hostname
	$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM.Guest.Hostname)
	$regKey= $reg.OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk",$true)

Or you can combine a read, set and verify.

ForEach ($VM in $VMs) {
	$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $VM.Guest.Hostname)
	Write-Host "Registry Value Before: "$VM.Guest.HostName "-" $reg.OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk\").GetValue("TimeoutValue")

	$regKey= $reg.OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk",$true)

	Write-Host "Registry Value After:  "$VM.Guest.HostName "-" $reg.OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk\").GetValue("TimeoutValue")

or be bold and set it in a one liner:

Get-VM "WEBSERVER*" | Where { $_.PowerState -eq "PoweredOn" } | %{[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_.Guest.Hostname).OpenSubKey("SYSTEM\CurrentControlSet\Services\Disk",$true).SetValue('TimeoutValue',190,'DWord')}

Powershell…you gotta love it!