Tag Archives: PowerCLI

VMware PowerCLI 5.8 R1 Released

imageToday VMware released PowerCLI 5.8 R1, in this release they add even more automation awesomeness to this already powerful tool.  It supports all the way back to vCenter and ESXi 4.1 so if your using this version or anything above this I think it’s well worth updating PowerCLI to make sure you take advantage of the new features, speed increases and bug fixes in this version.

The following list is an overview of the new features:

Faster startup – Enhancements have been made to improve the start-up speed of the first PowerCLI cmdlet in a session to ensure access to PowerCLI is now faster, this was something that I know was an issue in the past and Clint Kitson did an excellent post on things to check and making things faster, whilst the PowerCLI team handles manually compiling the .NET PowerCLI Serializers (notice the installer takes a couple of seconds longer) Clints post is still worth checking out as he lists some other things which can also help with the startup speed.

You can now manage storage policies with the Storage Policy-Based Management (SPBM) cmdlets. This functionality is included in a new snap-in for storage, which contains the following cmdlets:

  • Export-SpbmStoragePolicy
  • Get-SpbmCapability
  • Get-SpbmCompatibleStorage
  • Get-SpbmEntityConfiguration
  • Get-SpbmStoragePolicy
  • Import-SpbmStoragePolicy
  • New-SpbmRule
  • New-SpbmRuleSet
  • New-SpbmStoragePolicy
  • Remove-SpbmStoragePolicy
  • Set-SpbmEntityConfiguration
  • Set-SpbmStoragePolicy

This one is awesome and will ensure PowerCLI is an awesome tool for installing the vCloud Suite products, enhancements have been made to support deployment of OVF and OVA files with configuration parameters in the following areas:

  • Get-OVFConfiguration allows you to query an OVF or OVA for deployment properties
  • Import-vApp now has an OvfConfiguration parameter which allows for OVFProperties to be passed during deployment

Following the work in previous releases on automation of tags, you can now filter multiple objects by tag information. A tag parameter has been added to the following cmdlets:

  • Get-Cluster
  • Get-DatastoreCluster
  • Get-Folder
  • Get-ResourcePool
  • Get-DistributedSwitch
  • Get-Datacenter
  • Get-VApp

Enhancements have been made to error reporting by including more details in the error messages returned by the cmdlets, this includes more information from the APIs making sure users have the best information available when diagnosing why vCenter failed with a task.

You can now pass SpbmStoragePolicy objects to the RelatedObject parameter of the Get-HardDisk and Get-VM cmdlets.

You can now provide a filter when working with Datastore Providers.

You can now filter on DistributedSwitch and VMHost when using the Get-VMHostNetworkAdapter cmdlet with provided parameters.

You can now work with vCloud Director and vCloud Air with support for the latest version of the vCloud Director APIs, again a great enhancement and less pain when working with the latest vCD APIs as you no longer need to force the API version for it to work correctly.

vCloud Director cmdlets have been extended to include the New-CIVM and Get-CIVMTemplate cmdlets.

The New-CIVapp cmdlet has been extended with a new parameter set, which allows you to create an empty vApp.

You can now work with the enhanced vCenter Site Recovery Manager 5.8 public APIs,these have been extended by the SRM release and PowerCLI will enable automation of even more areas now!

Download

So why are you still reading this post?  Go download it now! or if you are a vCloud tenant you may want to just download the cmdlets that enable you to work with vCloud as a user from here.

WebCommander goes Open Source

You may have heard me talk about Webcommander before at VMworld or during a vBrownbag, if you haven’t and you don’t know about this project then you have been missing out!

WebCommander was designed as a framework to wrap your PowerShell and/or PowerCLI scripts into an easy-to-access web service, give each script a nice easy web form and show the results, give a simple icon on a web page to your end users and allow them to use your scripts and all they need is a web browser!

Have you ever wanted to give your users access to certain virtual infrastructure tasks instead of the entire vCenter Client? Have you ever written tasks in PowerShell which you wished you could easily hand off to the users to run on an ad-hoc basis? Now you can hand off the tasks your users need by simply adding a new script and giving them access to WebCommander.

Previously WebCommander was initially released as a VMware fling and updates were performed by VMware, the community was keen to jump on this and the feedback came in thick and fast, I was amazed to see how some customers were using WebCommander and how they took it to the next level.  The main engineer on the project (Jerry Liu) implemented the feedback fast and released update after update to bring the additions to the latest version.

The final part of this story and the great part is that Jerry has now released WebCommander to the community as an open source project on Github, this is fantastic news as it means more people can now get involved, add new contributions and make changes which can be checked back into the core code for everyone to use.  PowerCLI and PowerShell users alike.

So why wait, head over to the site here, download and contribute to this awesome project!

 

WebCommander Eye candy

image

Introduction to PowerCLI

Whenever I visit VMUGs or talk about PowerCLI I am constantly surprised by people who have not yet heard of PowerCLI or are unaware of the basics of how it works, let alone the power it has and time it can save people.  I wanted to address this and give people a head start learning PowerCLI.

The below video gives you an idea of what PowerCLI is, how it works and how you can get started. It’s the first of what will hopefully be a series of videos on PowerCLI concepts, please add a comment here for the kind of videos you would like to see.

Creating a manual VSAN Cluster with PowerCLI

In my previous post I showed how to create a datacenter, cluster, add hosts and create an automatic VSAN cluster allowing for the local SSDs and HDDs to be added to a new VSAN datastore, check it out here.

But what if you wanted to create a manual VSAN cluster and select the disks to add to the VSAN Diskgroup to create the datastore, this gives more control and allows for a precisely configured environment making the most of local resources and perhaps saving other disks for further use and alternate features.

In the below code you can see that instead of automatic we can easily set the cluster to manual and add the disks ourselves, with my code I have selected the disks I want to use as all blank SSDs and all HDDs but you could easily use PowerCLI to define the make, model, size or other factors to use before creating the diskgroup and manually adding the SSDs and HDDs.

Output

SNAGHTML15bb0de

The script

import-module VMware.VimAutomation.Extensions
Connect-VIServer 172.16.78.191 -User root -Password vmware
$Datacenter = "DC01"
$Cluster = "VSAN Cluster"
$ESXHosts = "172.16.78.129", "172.16.78.130"
$ESXUser = "root"
$ESXPWD = "vmware"
$VMKNetforVSAN = "Management Network"

# If doesnt exist create the datacenter
If (-Not ($NewDatacenter = Get-Datacenter $Datacenter -ErrorAction SilentlyContinue)){ 
	Write-Host "Adding $Datacenter"
	$NewDatacenter = New-Datacenter -Name $Datacenter -Location (Get-Folder Datacenters) 
}

# Create the initial cluster
if (-Not ($NewCluster = Get-Cluster $Cluster -ErrorAction SilentlyContinue)) { 
	Write-Host "Adding $Cluster"
	$NewCluster = New-Cluster -Name $Cluster -Location $NewDatacenter 
}

# For each of our hosts
$ESXHosts | Foreach {
	Write-Host "Adding $($_) to $($NewCluster)"
	# Add them to the cluster
	$AddedHost = Add-VMHost -Name $_ -Location $NewCluster -User $ESXUser -Password $ESXPWD -Force
	# Check to see if they have a VSAN enabled VMKernel
	$VMKernel = $AddedHost | Get-VMHostNetworkAdapter -VMKernel | Where {$_.PortGroupName -eq $VMKNetforVSAN }
	$IsVSANEnabled = $VMKernel | Where { $_.VsanTrafficEnabled}
	# If it isnt Enabled then Enable it
	If (-not $IsVSANEnabled) {
		Write-Host "Enabling VSAN Kernel on $VMKernel"
		$VMKernel | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false | Out-Null
	} Else {
		Write-Host "VSAN Kernel already enabled on $VmKernel"
		$IsVSANEnabled | Select VMhost, DeviceName, IP, PortGroupName, VSANTrafficEnabled
	}
}
# Enable VSAN on the cluster and set to Automatic Disk Claim Mode
Write-Host "Enabling VSAN on $NewCluster"
$VSANCluster = $NewCluster | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Manual -Confirm:$false -ErrorAction SilentlyContinue

$ESXHosts | Foreach {
	Write-Host "Finding disks for $($_)"
	# Find the blank SSDs for the current host
	$disks = Get-VMHost $_ | Get-VMHostDisk
	$SSDs = $disks | Where { $_.scsilun.extensiondata.ssd }
	$BlankSSDs = $SSDs | Where { -not $_.Extensiondata.Layout.Partition[0].partition }
	Write-Host "Blank SSDs"
	$BlankSSDsArray = ""
	$BlankSSDs | Foreach { $BlankSSDsArray += $_.scsilun.CanonicalName }
	$BlankSSDsArray
	
	# Find the blank Magnetic disks for the current host
	$HDDs = $disks | Where { -not $_.scsilun.extensiondata.ssd }
	$BlankHDDs = $HDDs | Where { -not $_.Extensiondata.Layout.Partition[0].partition }
	Write-Host "Blank HDDs"
	$BlankHDDsArray = ""
	$BlankHDDs | Foreach { $BlankHDDsArray += $_.scsilun.CanonicalName }
	$BlankHDDsArray
	
	New-VsanDiskGroup -VMHost $_ -SSDCanonicalName $BlankSSDsArray -DataDiskCanonicalName $BlankHDDsArray | Out-Null
}

If ($VSANCluster.VSANEnabled){
	Write-Host "VSAN cluster $($VSANCLuster.Name) created in $($VSANCluster.VSANDiskClaimMode) configuration"
	Write-Host "The following Hosts and Disk Groups now exist:"
	Get-VsanDiskGroup | Select VMHost, Name | FT -AutoSize
	Write-Host "The following VSAN Datastore now exists:"
	Get-Datastore | Where {$_.Type -eq "vsan"} | Select Name, Type, FreeSpaceGB, CapacityGB
} Else {
	Write-Host "Something went wrong, VSAN not enabled"
}

Creating a VSAN Cluster with PowerCLI

Recently there was a new fling released on the VMware Flings site, this enables us to use VSAN and VMware Flash Read Cache with PowerCLI, check out the site here for more details.

I wrote a post on the PowerCLI Blog which showed the cmdlets and some examples on how you might use these, recently I had the chance to put them to use when I needed to stand up a new VSAN cluster, I was able to easily build myself a test cluster with the help of Williams post here.

Once I had a couple of hosts and my fresh vCenter server, I used the following script to setup the Datacenter, Cluster, add the hosts, enable the VSAN VMKernel port and enable VSAN in automatic mode.  The cmdlets are very easy to use and I was amazed at how easy and quick it is to setup VSAN.

Output

VSAN

The script

import-module VMware.VimAutomation.Extensions
Connect-VIServer 172.16.78.191 -User root -Password vmware
$Datacenter = "DC01"
$Cluster = "VSAN Cluster"
$ESXHosts = "172.16.78.129", "172.16.78.130"
$ESXUser = "root"
$ESXPWD = "vmware"
$VMKNetforVSAN = "Management Network"

# If doesnt exist create the datacenter
If (-Not ($NewDatacenter = Get-Datacenter $Datacenter -ErrorAction SilentlyContinue)){ 
	Write-Host "Adding $Datacenter"
	$NewDatacenter = New-Datacenter -Name $Datacenter -Location (Get-Folder Datacenters) 
}

# Create the initial cluster
if (-Not ($NewCluster = Get-Cluster $Cluster -ErrorAction SilentlyContinue)) { 
	Write-Host "Adding $Cluster"
	$NewCluster = New-Cluster -Name $Cluster -Location $NewDatacenter 
}

# For each of our hosts
$ESXHosts | Foreach {
	Write-Host "Adding $($_) to $($NewCluster)"
	# Add them to the cluster
	$AddedHost = Add-VMHost -Name $_ -Location $NewCluster -User $ESXUser -Password $ESXPWD -Force
	# Check to see if they have a VSAN enabled VMKernel
	$VMKernel = $AddedHost | Get-VMHostNetworkAdapter -VMKernel | Where {$_.PortGroupName -eq $VMKNetforVSAN }
	$IsVSANEnabled = $VMKernel | Where { $_.VsanTrafficEnabled}
	# If it isnt Enabled then Enable it
	If (-not $IsVSANEnabled) {
		Write-Host "Enabling VSAN Kernel on $VMKernel"
		$VMKernel | Set-VMHostNetworkAdapter -VsanTrafficEnabled $true -Confirm:$false | Out-Null
	} Else {
		Write-Host "VSAN Kernel already enabled on $VmKernel"
		$IsVSANEnabled | Select VMhost, DeviceName, IP, PortGroupName, VSANTrafficEnabled
	}
}
# Enable VSAN on the cluster and set to Automatic Disk Claim Mode
Write-Host "Enabling VSAN on $NewCluster"
$VSANCluster = $NewCluster | Set-Cluster -VsanEnabled:$true -VsanDiskClaimMode Automatic -Confirm:$false -ErrorAction SilentlyContinue
If ($VSANCluster.VSANEnabled){
	Write-Host "VSAN cluster $($VSANCLuster.Name) created in $($VSANCluster.VSANDiskClaimMode) configuration"
	Write-Host "The following Hosts and Disk Groups now exist:"
	Get-VsanDiskGroup | Select VMHost, Name | FT -AutoSize
	Write-Host "The following VSAN Datastore now exists:"
	Get-Datastore | Where {$_.Type -eq "vsan"} | Select Name, Type, FreeSpaceGB, CapacityGB
} Else {
	Write-Host "Something went wrong, VSAN not enabled"
}

Remotely Managing VMware vSphere through your mobile device

Remember the VMware Community PowerPack for PowerGUI? With it we were able to manage our VMware environment through a MMC style GUI placed on top of PowerCLI Scripts, this gave us the benefit of custom task based actions with a nice and easy to use interface.

Now Imagine if you could have the same great customized management options for your vSphere environment on a mobile device or tablet device.  Imagine no longer!

Mobile IT

Mobile IT is a new application which is available on a number of different mobile devices and tablets that allows us to import Mobile Packs which are custom written packs that work with your applications and also Power Packs which were previously written for PowerGUI.

So What do I need?

The Server

The first thing you will need to do is setup the server which is going to run Mobile IT, this is where we have two options.  In a corporate environment you will probably want all connections to go straight to your systems and you will want to manage the traffic and every aspect of the environment, in this case you would have the Mobile IT Server in your DMZ and the Mobile IT Agent on your network as per the image below taken from the Mobile IT documentation.

TinyGrab Screen Shot 12-01-2014 17.55.30

The second option (which was perfect for my home lab) is where Dell hosts the gateway server for you, you can then install the Mobile IT Server and Agent on your network (I had them both on the same server) as per the below diagram taken from the Mobile IT documentation.

TinyGrab Screen Shot 12-01-2014 17.55.08

The Install was very easy and I had the system up and running in around 20 minutes, once setup it was easy to import the VMware Community Power Pack and add the same machine as a new instance in the web admin interface.  I also installed PowerCLI on this server which is needed by the Community PowerPack.

TinyGrab Screen Shot 12-01-2014 18.58.46

The Client

Now all you need to do is install the app on your phone or tablet, a client is available in the app store of each of the following devices and is currently free. Once downloaded and you have entered your company name and credentials it will communicate with your Mobile IT server where you can authorize the device for use on your network.

Download

Check out the Mobile IT Site here for downloads and documentation.

See it in action

See it in action with the VMware Power Pack below and remember, this is all based on PowerCLI so you can customize the scripts and allow access to your tasks from any mobile device.

PowerCLI Group Discussion

VMworld PowerCLI Group Discussion–Part 3–Launching and Using

image

Following on from the previous posts in this series, this post will take us through the group discussion held at VMworld this year and expand on the items noted during the session.

This post will focus on what people in the session used PowerCLI for and also the various ways people used to launch the scripts.

Continue reading

PowerCLI Group Discussion

VMworld PowerCLI Group Discussion–Part 2–Resources

ResourcesFollowing Part 1 of these posts where we discussed getting started in PowerCLI I now give you Part 2 of the note taking by Nigel Boulton at VMworld in the PowerCLI Group Discussion.

In this part of the session we discussed what resources were available to people using PowerCLI.

As with the previous post I will expand on the notes taken and give you the complete list below.

If you have more resources make sure you add a comment and share them with others.

Continue reading

PowerCLI Group Discussion

VMworld PowerCLI Group Discussion–Part 1–Getting Started

imageAlways my favorite session at VMworld, the group discussion gives others a chance to share their experience and give their view on a product.

I have hosted a PowerCLI Group Discussion for the past 2 years and have found them a great way to learn and share information.

This year with some great note taking by my beautiful assistant Nigel Boulton I thought it would be useful to type up these notes from the session and share them on my blog.

Continue reading