New to PowerCli.
My problem is attempting to create a report on selected Virtual Machines that have a specific value in a custom attribute I've created.
I have created a Custom Attribute named PowerDownStage of type 'Virtual Machine', the VMs have entries valued between 1 and 5.
I need to get a list of VMs with, for example, value of 3 exported into a csv file.
The command I've created (below) does return a list however, it returns a list of all VMs and the PowerDownStage value and not filtered by PowerDownStage - eq "3"
Grateful for any advice please?
get-VM | get-annotation -CustomAttribute "PowerDownStage" |
select AnnotatedEntity,Value
@{N="Value";E={$key = $_.AvailableField | where {$_.PowerDownStage -eq "3"} | Select -ExpandProperty Key
$_.CustomValue | where {$_.Key -eq $key} | Select -ExpandProperty Value}}
Try something like this
Get-VM | Get-Annotation -CustomAttribute "PowerDownStage" |
where {$_.Value -eq 3} |
select @{N='VM';E={$_.AnnotatedEntity}},Value |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This works great. All I need to do now is to add a value to "PowerDownStage" attribute for each VM listed in an excel spreadsheet.
Thanks for your help.
Lynwen
You mean like this?
select @{N='VMHost';E={$_.AnnotatedEntity}},Name,Value |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference