Add my own custom properties and populate them with powershell in VMM2012
I have made a powershell script function to update information about what VLAN and IP the VM´s have. This for the IT Admin to easily see in the VMM 2012 Console. Of course the function can be customized to populate any other information available for the VM´s, maybe you want to display create date or something else that is not in the standard properties and you do not want to use the pre-made custom# .
I am using the Get-IPAddress from Ben Wilkinson, This requires that the VMM server can resolve the IP of the VM´s from a DNS.
If I do not have an DNS or the VLAN info is not stored, i can via the parameters update the properties by -IP or -VLANid.
As you can see on this screen dump, by default i only have custom#, to add my own i have to click on “Manage Custom Properties”
Here i press “Create” and add a name and optionally a description
Then when i have created the custom properties i want i add them,
Then it looks like this,
Now the powershell function comes into play when i am going to populate these fields with information.
function Set-CustomValue{
# Function to add custom data on VMs
#
# Niklas Akerlund /RTS 2012-02-18
param (
[Parameter(Position=0,Mandatory=$true,HelpMessage="A virtual machine pleaze",
ValueFromPipeline=$True)]
$VM,
$VLANid = "",
$IP = ""
)
. .\Get-IPAddress.ps1
$VM = Get-SCVirtualMachine $VM
$CustomIP = Get-SCCustomProperty -Name "IP"
$CustomVLAN = Get-SCCustomProperty -Name "VLAN"
if ($IP -eq ""){
$IP = Get-IPAddress -HostName $VM.Name
}
if ($VLANid -eq ""){
$VMnics = $VM | Get-SCVirtualNetworkAdapter
if($VMnics.Count -ne $null){
foreach ($VMnic in $VMnics){
$VLANid = $VLANid + $VMnic.VlanID + " "
}
Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomVLAN -Value $VLANid
}else{
Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomVLAN -Value $VMnics.VlanID
}
}else {
Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomVLAN -Value $VLANid
}
if($IP -ne ""){
Set-SCCustomPropertyValue -InputObject $VM -CustomProperty $CustomIP -Value $IP
}
}
a screendump of my powershell console, as you can see I am using the (Get-SCVMHostCluster).Nodes to get all virtual machines on these, also i am using a foreach (%) to run the population on each VM.
And this is how it looks in the VMM console,






Really love the idea of this but can’t get it to work. after running the command:
(Get-VMHostCluster cluster01).Nodes | Get-SCVirtualMachine | %{Set-CustomValue -VM $_} | ft Name,Value
All I get is the cursor returning to a new command prompt and no output (Errors or otherwise.)
I am fairly new to PowerShell, any tips like being able to turn on error checking to see if I have missed anything out?
Cheers
the | ft Name,Value just shows the values, the idea here is that you populate the custom properties on your SCVMM 2012 console. if you test with one VM as in Get-SCVirtualMachine XXNAME-VM | Set-CustomValue you should see on that machines properties that it has populated the custom fields.. as i write in the post you can also use the parameters for -Vlan -IP to just test that it works, this function also requires that you save the Get-IPadress function in the link.
this is really great, however do you have a way to extract these custom properties for backup? I used to use an old SCVMM 2008 script but this doesn’t allow me to extract Custom Properties I have set like “server use” “License” etc (that have been manually entered) So could I run a powershell script to extract all of the metadata and reimport in case of failure?
This information is something that i populate with a scheduled task, The information is not static as the VM´s can change vlan and ip,
You should be able to do a export of VM name and custom property and then import if disaster, It is supported to do an upgrade from VMM 2008 r2 sp1 -> VMM 2012