$Filename = "C:\MyInformation.csv"
Connect-VIServer MYSERVER
$myCol = @()
Foreach ($VM in (Get-View -ViewType VirtualMachine |Sort Name)){
$MYInfo = "" |select-Object VMName,CPUReservation,CPULimit,CPUShares,MEMSize,MEMReservation,MEMLimit,MEMShares
$MYInfo.VMName = $VM.Name
$MYInfo.CPUReservation = $VM.Config.CpuAllocation.Reservation
If ($VM.Config.CpuAllocation.Limit-eq "-1"){
$MYInfo.CPULimit = "Unlimited"}
Else{
$MYInfo.CPULimit = $VM.Config.CpuAllocation.Limit
}
$MYInfo.CPUShares = $VM.Config.CpuAllocation.Shares.Shares
$MYInfo.MEMSize = $VM.Config.Hardware.MemoryMB
$MYInfo.MEMReservation = $VM.Config.MemoryAllocation.Reservation
If ($VM.Config.MemoryAllocation.Limit-eq "-1"){
$MYInfo.MEMLimit = "Unlimited"}
Else{
$MYInfo.MEMLimit = $VM.Config.MemoryAllocation.Limit
}
$MYInfo.MEMShares = $VM.Config.MemoryAllocation.Shares.Shares
$myCol += $MYInfo
}
$myCol |Export-csv -NoTypeInformation $Filename
Category Archives: PowerShell
Check Cluster Configurations
Hugo has been pushing out some nice scripts recently and his latest is a cracker…
This Powershell script generates an overview of any items that a
re not available to every ESX server in a VMware cluster. These items might prevent your vm’s being vmotioned by DRS or restarted by HA. Pretty serious business, I’d say!
The items involved are:
1. datastores
2. LUNs (important when using Raw Device Mappings)
3. port groupsThe output is a nicely formatted HTML page showing not only which items are misconfigured, but also where the are available and where they are absent.
Download it here and check out his site for some more amazing scripts.
Powershell Workstation/Server Audit script update
Following some great comments from Jeffrey Snover and other PowerShell Guru’s on the previous version of my Audit script I have now re-written the script to incompas some of the superior wisdom emparted upon me.
So what does this mean ?
- I am now using a string to store all the html code as I build it up through the script as blogged by Jeffrey here
- I am now using $env:computername rather than localhost – Thanks to Jeffrey Hicks, your right it does look better !
- I am breaking from my switch statements correctly (schoolboy error on my part)
- I am now using a terminating error where needed
- I have changed the keyboard map switch statement into a hashtable
- The code is now over 100 lines shorter and now fits into http://poshcode.org (Cool)
The Bad News
Jeffreys parting comment was:
It would be a lot faster as well.
Again – awesome script!
Cheers.
Jeffrey Snover [MSFT]
Unfortunatly although I will agree with the awesome script part when I ran some tests to see if the script ran faster, which I was convinced it would, mainly due to only writing the content out at the end rather than one line at a time I had some supprising results:
PS C:\Audit> measure-command {& “C:\Audit\OldAudit.ps1”}
Days : 0
Hours : 0
Minutes : 0
Seconds : 14
Milliseconds : 57
Ticks : 140570477
TotalDays : 0.000162697311342593
TotalHours : 0.00390473547222222
TotalMinutes : 0.234284128333333
TotalSeconds : 14.0570477
TotalMilliseconds : 14057.0477
PS C:\Audit> measure-command {& “C:\Audit\Audit.ps1”}
Days : 0
Hours : 0
Minutes : 0
Seconds : 18
Milliseconds : 480
Ticks : 184803922
TotalDays : 0.000213893428240741
TotalHours : 0.00513344227777778
TotalMinutes : 0.308006536666667
TotalSeconds : 18.4803922
TotalMilliseconds : 18480.3922
Can anyone shed any light on this as frankly I’m baffled ?!
Thanks again for all the comments on the script and the new version is below:
A sample of the output can be viewed here (best viewed in Internet Explorer):
List VM’s with RDM
I was asked if it was possible to list all VM’s with Raw Disk Mappings on twitter, a quick search of the VI Toolkit community showed that LucD had already achieved this, I have copied the code below for reference:
Connect-VIServer MYVISERVER $report = @()$vms = Get-VM | Get-View foreach($vm in $vms){ foreach($dev in $vm.Config.Hardware.Device){ if(($dev.gettype()).Name -eq "VirtualDisk"){ if($dev.Backing.CompatibilityMode -eq "physicalMode"){ $row = "" | select VMName, HDDeviceName, HDFileName $row.VMName = $vm.Name $row.HDDeviceName = $dev.Backing.DeviceName $row.HDFileName = $dev.Backing.FileName $report += $row } } }}$report
Powershell V2 CTP3
They said it would be December and Microsoft actually kept a deadline… Only Just !
Powershell V2 CTP3 was released last night after several hints from @jsnover on twitter.
To download the latest Community Technology Preview here
Selected New and Updated Features in Windows PowerShell V2 CTP3
New VMWare Powerpack for PowerGui
Supported features:
- Management of multiple VMware Virtual Center, ESX, ESXi and VMware Server hosts when using the VMware VI Toolkit 1.0 release
- Management of multiple VMware Virtual Center, ESX and ESXi hosts when using the VMware VI Toolkit 1.5 release
- Single sign-on to multiple hosts using the same credentials
- Ability to browse through inventory hierarchies on Virtual Center
- Ability to view topological data for any managed server
- Management of datacenters, clusters, resource pools, hosts, folders, virtual machines, templates, snapshots, networks, datastores, files, tasks and log files
Latest Version:
December 19, 2008 (2.0.0)
– reorganized the PowerPack structure to facilitate easier management of multiple hosts and to allow users to retrieve objects from one or more of the hosts they are managing whether they are already connected or not
– added support for browsing the VMware Inventory hierarchy (includes Hosts and Clusters, Virtual Machines and Templates, Networks and Datastores), including being able to browse directly into the file system on the datastores
– added many new links and actions
– exposed many more VMware Infrastructure objects through topological views and through integration in the hierarchy
– improved the performance of many nodes, links and actions
– added single sign-on support (note that connecting to multiple hosts using the same username but different passwords is currently not supported, but we are working on that and will provide support for this soon)
– tested management against Virtual Center 2.0, ESX 3.0x and 3.5, ESXi 3.5 and Virtual Server 2.0 (note: management of Virtual Center 2.0 requires version 1.0 of the VMware VI Toolkit)
– and more!
Extra fields in the VI Client
How would you like extra fields in the VI Client, maybe a field for if the VM has a snapshot or even the host hardware model or ESX version. Well now you can.
Hugo Peters has been creating some amazing scripts which put data back into the VI Client for you to use, check out his posts:
Add Snapshot Information to the VI Client using Powershell
Add Custom Fields to VI Client with Powershell (Samples)
Great work Hugo.
PrimalForms Example (Virtual Center Log)
Fatbeard (don’t ask as I don’t know) has been reading my blog, he saw the VI Toolkit script I produced for getting events out of the virtual center database and has put a nice GUI on top of the whole thing to create a really nice usable app.
Top 10 PowerShell Scripts
Eric Siebert has published his list of the Top 10 PowerShell scripts that VMware administrators should use there are some good ones on here that are worth checking out, can’t believe I made number 2 ! Thanks Eric.
Report into MS Word
http://communities.vmware.com/docs/DOC-7070
A script from Alan Renouf that provides a report in Microsoft Word of the virtual machines in your environment with graphs and pie charts.
Detailed VMware Host Network Information
Following my previous script ‘Extracting Cisco Discovery Protocol Info‘ I decided to tidy up the script, give a more controlled output and add a few items to the output.
The following script will add some nice host network information into an object which is exported to a csv file for passing to the network guys or can be used to find your server in that mess of cables that are always meaning to be tidied in the data center.
You will get:
- Host,
- Physical Nic Name
- Speed
- MAC
- Switch Device ID
- Port ID
- Observed Network ranges
- VLAN’s



Report into MS Word