N
N
Nathair2015-10-09 21:34:07
PowerShell
Nathair, 2015-10-09 21:34:07

How to get CustomProperty values ​​of VMM System Center VM via Powershell by selected property name?

I have created custom properties for Hyper-V virtual machines through the Virtual Machine Manager snap-in
The main task is to upload a CSV report of virtual machines, which will include custom properties. To do this, I need to first get them:
Get-VM | ForEach {
$scVM = Get-SCVirtualMachine -Name $_.Name
$props = @{
HostName = $_.HostName
Name = $_.Name
ComputerName = $_.ComputerName
Status = $_.Status
StopAction = $_.StopAction
StartAction = $_.StartAction
CustomProperty7 = ($scVM.CustomProperty | Where { $_.Name -like 'CustomProperty7' }).Values
​​}
New-Object PsObject -Property $props
} | Select-Object HostName, Name, ComputerName, Status, StopAction, StartAction, CustomProperty7
But for some reason it outputs all the desired properties of the VM object except CustomProperty
when trying to select all custom properties of a specific virtual machine
$cf = (Get-VM | where {$_ .Name -eq 'VirtualMachine'}).CustomProperty
$Project = ($cf | where {$_.Name -like ''}).Values
​​$Project
it shows the custom property names and values ​​that I put in the machine settings
however when trying to extract the value of a specific custom property
$cf = (Get-VM | where {$_.Name -eq 'VirtualMachine'}).CustomProperty
$Project = ($cf | where {$_.Name -like 'CustomProperty7'}).Values
​​$Project returns null
because it doesn't find a property with that name, but it exists and the name matches the requested one.
Tell me how to make this garbage fly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question