In my lab I have several types of storage for my guests, like 7K over SMB3, SSD over SMB3 or local storage. I thought it would be nice to see which storage my guests were on right there in the VMM console, so i created custom property and made myself a simple little powershell function to populate the property for all the VM’s. I could have made a script, but making functions in module files allows for easy re-/cross use of scripts.
I will not go into details on how to make a custom property right now, as there are plenty of articles on how to do this. I will instead concentrate on the powershell function. If you decide to “steal” it, please retain the Created by line/original author.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
<# .SYNOPSIS Sets a custom property called StorageType on all vms managed by a vmm server .DESCRIPTION Sets a custom property called StorageType on all vms managed by a vmm server. The custom property StorageType must first be created before the function can be used. It can also clear the Tag property for all vms managed by same vmm. Does not remove values in Tag property by default. .PARAMETER VMMServerName The name of the VMM server to run the command on .PARAMETER ClearTag Clears the Tag property in VMM for all VMs .EXAMPLE Set-JRSCVMStorageType -VMMServerName vmmserver.domain.local .EXAMPLE Set-JRSCVMStorageType -VMMServerName vmmserver1 -ClearTag .INPUTS System.String .NOTES =========================================================================== Created on: 06.04.2017 09.46 Created by: Jan Ryen Mail: jan@janryen.com Filename: Set-JRSCVMStorageType.psm1 =========================================================================== .DESCRIPTION Sets a custom property called StorageType on all vms managed by a vmm server .LINK about_functions_advanced .LINK about_comment_based_help #> function Set-JRSCVMStorageType { [cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact='low')] param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string]$VMMServerName, [switch]$ClearTag=$false ) $CustomStorageType = Get-SCCustomProperty -Name "StorageType" $guests = @(Get-SCVirtualMachine -VMMServer $VMMServerName ) foreach ($guest in $guests) { $loc = $guest.VirtualHardDisks[0].Location write-host "VHDX for $guest is: $loc " if($ClearTag.IsPresent) { $guest | Set-SCVirtualMachine -Tag "" write-host "Switch ClearTag True - Clearing all Tags" } else { write-host "Switch ClearTag False - NOT clearing all Tags" } if ($guest.VirtualHardDisks[0].Location -like "*storage0*" ) { Set-SCCustomPropertyValue -InputObject $guest -CustomProperty $CustomStorageType -Value "SMB3-S0" write-host "Setting Value SMB3-S0" } elseif ($guest.VirtualHardDisks[0].Location -like "*storage3*") { Set-SCCustomPropertyValue -InputObject $guest -CustomProperty $CustomStorageType -Value "SMB3-S3" write-host "Setting Value SMB3-S3" } elseif ($guest.VirtualHardDisks[0].Location -like "*ClusterStorage*") { Set-SCCustomPropertyValue -InputObject $guest -CustomProperty $CustomStorageType -Value "CSV" write-host "Setting Value CSV" } else { Set-SCCustomPropertyValue -InputObject $guest -CustomProperty $CustomStorageType -Value "LOCAL" write-host "Setting Value LOCAL" } } } |
Here is what that looks like in the console after running the function.