Archive for June, 2009
PowerCLI: vProfiles
Jun 29th
Following my recent post, Easy vSwitch & PortGroup Setup I thought I would give PrimalForms a go and create a quick GUI, PrimalForms is a great app from Sapien which allows you create form based windows for which it gives you the PowerShell code, this means no install and yet the users still get a great looking GUI.
It turned out pretty good, even if I do say so myself.
Here’s what the script allows you to do:
- Compares one host to another
- Copies vSwitches if they do not currently exist
- Copies PortGroups + VLAN Tags if they do not currently exist
What it doesn’t do at the moment is copy any of the custom settings for the vSwitches or PortGroups.
This is still very much a V1 and it will be added to, I hope to include other areas such as the NTP servers, advanced host configuration etc, if you have an idea then please add it to the comments and I will see what I can do.
To see this in action please check out the below video, this script can easily be run straight from the PowerCLI prompt also.
vProfiles from Alan Renouf on Vimeo.
PowerCLI: Easy vSwitch & PortGroup Setup
Jun 27th
To get VMotion working the networking setup plays a big part, any of the following could cause you big issues:
- A spelling mistake in a PortGroup name
- A missing PortGroup
- A PortGroup configured incorrectly
- A non-existing PortGroup on one of your hosts
- etc
This is why automation and PowerCLI is key to the setup of your vSwitches and PortGroup’s, you could add each vSwitch manually and then create a PortGroup for each VLAN you have trunked to your hosts manually but what are the chances you will miss one, what are the chances you will get the VLAN ID incorrect ? And you sure do get bored of the wizard when you have 4 vSwitches and around 20 PortGroups !
The following code will take you through copying all vSwitches and PortGroups from an existing ESX server over to a new server, ensuring they are exactly the same. It sure does save me time !
$VISRV = Connect-VIServer (Read-Host "Please enter the name of your VI SERVER")
$BASEHost = Get-VMHost -Name (Read-Host "Please enter the name of your existing server as seen in the VI Client:")
$NEWHost = Get-VMHost -Name (Read-Host "Please enter the name of the server to configure as seen in the VI Client:")
$BASEHost |Get-VirtualSwitch |Foreach {
If (($NEWHost |Get-VirtualSwitch -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
Write-Host "Creating Virtual Switch $($_.Name)"
$NewSwitch = $NEWHost |New-VirtualSwitch -Name $_.Name-NumPorts $_.NumPorts-Mtu $_.Mtu
$vSwitch = $_
}
$_ |Get-VirtualPortGroup |Foreach {
If (($NEWHost |Get-VirtualPortGroup -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
Write-Host "Creating Portgroup $($_.Name)"
$NewPortGroup = $NEWHost |Get-VirtualSwitch -Name $vSwitch |New-VirtualPortGroup -Name $_.Name-VLanId $_.VLanID
}
}
}
PowerCLI: More One Liners
Jun 25th
On my previous post where we counted how many VMs were on each host and the cluster they were in I was asked a couple of questions:
1. How about listing the number of VMs per Resource Pool?
2. How can we extend this to get the templates as well ?
Ok, easy stuff (I thought).
Lets take them in turn…
Question 1. How about listing the number of VMs per Resource Pool?
What you need to remember about this is that even if a VM is not in a resource pool it still has resources available to it which have to come from somewhere so in fact what VMware do behind the scenes is have a hidden resource pool called ‘Resources’ where it places the VM when it is not in any other resource pool.
If you remember this then yes, it is quite easy as below:
Get-ResourcePool | Where {$_.Name -ne “Resources“ }| Select Name, @{N=“NumVM“;E={($_ | Get-VM).Count}} | Sort Name|Export-Csv -NoTypeInformation c:\res-numvm.csv
All we needed to do was to put a Where statement in there to not count the VMs in the ‘pre-made resource pool’
Question 2. How can we extend this to get the templates as well ?
Ahhh, this one is simple I thought, all we need to do is put a count in for Get-Template so the one-liner looks like this:
Get-VMHost |Select @{N=“Cluster“;E={Get-Cluster -VMHost $_}},Name, @{N=“NumVM“;E={($_ |Get-VM).Count}}, @{N=“NumTemplates“;E={($_ |Get-Template).Count}} |Sort Cluster,Name |Export-Csv -NoTypeInformation c:\clu-host-numvm-numtempl.csv
Unfortunately as a Template is basically a special type of VM the cmdlets don’t work like this at the moment, you can not get a list of Templates which exist on a host without delving into the SDK so what I suggest you do is wait until the next version of PowerCLI is released and see if they have fixed this issue. – Current version is PowerCLI V4.0.0.1580
PowerCLI: Folder Name Mismatch
Jun 22nd
Isn’t it annoying when you are looking for a VM on your datastore and you cant find it because the folder name is not the same as the VM, use the below script and you will never have that problem again.
This script will compare the name of the VM to the folder it is stored in, any mismatches will be output.
I know a regex expert could probably do this better, let me know if you are one
Sample Output:
| VM | Path |
| New VM 1 | [storage1] New VM |
| ABCDEV01 | [storage1] Dev Test |
| MicroDS | [SAN11] New VM |
| VM127 | [SAN11] Windows 2003 Server |
PowerCLI: SnapReminder
Jun 22nd
Fed up of chasing those people who constantly create snapshots and leave them hanging around for weeks or even months on end ?
You no longer have to do the chasing, just use the following script to automatically find the offending snapshot, find the person who created it, get their email address from AD and send them an email reminding them of their mortal sin.
Unofficial Online VMware User Group #2
Jun 17th
Following the success of the first UOVMUG the second will be held on 29th June at 08:00 PM BST / 03:00 PM EDT, hopefully it will be more interactive as we should be running it through webex, make sure you have visited the webex site before the meeting so that everything is installed and working fine.
The Agenda at the moment is as follows:
- Introduction
- Presentation and Demonstration of vWire
- vCoffeebreak
- Presentation and Demonstration of Powerpath for ESX – by Mitch Berke, EMC Sr. VMware Specialist
- Finish and details of next Unofficial Online VMUG
- Find out more details and join on the UOVMUG Page
One Liner: How many VMs ?
Jun 17th
Ever wondered how many VM’s you have on each Host? You could manually check it or then again you could let powershell do the work for you:
Get-VMHost | Select @{N=“Cluster“;E={Get-Cluster -VMHost $_}}, Name, @{N=“NumVM“;E={($_ | Get-VM).Count}} | Sort Cluster, Name | Export-Csv -NoTypeInformation c:\clu-host-numvm.csv
Vote for Freedom vote for me (please)
Jun 16th
My only chance of getting to VMworld this year is to win a all expenses paid trip, luckly enough Veeam have launched a competition which I have entered and first prize is a all expenses trip to San Francisco -VMworld 2009.
I always add my scripts to this blog for free and now Im hoping you may be able to help me out by simply voting for me at the following location: Thanks in advance !
You will need to register to login but registration is only a 2 minute job.
Come on, we can’t let the woman in a bra beat me (No not you Gabe the other one)!
vSphere permissions: export & import – Part 1
Jun 15th
Short security principles intro
One aspect of your vSphere environment that shouldn’t be ignored is the built-in security feature that allows you to control who can do what with which vSphere entity.
Internally this is controlled from the AuthorizationManager. This object contains all the properties and methods you need to configure and manage the built-in security system.
The principle how vSphere entities are protected is quite straightforward.
At the basis are the so-called privileges. Each privilege describes a basic action that can be performed on one or more of the vSphere entities.
vSphere permissions: export & import – Part 2
Jun 14th
In Part1 of this article we had all the roles and permissions exported to an XML file. It’s now time to import the roles and permissions into a Virtual Center.
The script does in fact the reverse of what the script in Part 1 did.
But there were a few “gotchas“ that had to be solved before arriving at a working solution.
Duplicate Names
The script does not take into account that you can have different objects in your vSphere environment with the same name! Which imho is not a good practice in any case.
Should someone have the need for this functionality let me know and I will try to adapt the scripts.
Principals
The script does not create the principals that are mentioned in the XML file. If these principals do not exists in the environment where you want to import the roles and permissions the script will show errors.
Speed of execution
The permissions are set with an API called SetEntityPermissions.
As can be seen in the API Reference Guide this method requires a Managed Object Reference (MoRef) to a ManagedEntity. A ManagedEntity object is the parent object of most of the managed objects in vSphere.
This way of working avoids that there would have to be a separate method for each of the derived managed objects.






