Hi,
I would like to export in csc the list of my vm who have a specific tag.
i can do that but the powercli command extract the vm with all properties,
so i would like just the name of my vms.
i 'm blocked with this powercli command :
Get-VM | where {(Get-TagAssignment -Entity $_ | Select -ExpandProperty Tag) -like 'tag-1*'} | Export-CSV C:\Scripts\result\vms-tag-1.csv
thank you for your help.
Try like this
Get-VM | Get-TagAssignment |
where{$_.Tag -like 'tag-1*'} |
Select @{N='VM';E={$_.Entity.Name}} |
Export-CSV C:\Scripts\result\vms-tag-1.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try like this
Get-VM | Get-TagAssignment |
where{$_.Tag -like 'tag-1*'} |
Select @{N='VM';E={$_.Entity.Name}} |
Export-CSV C:\Scripts\result\vms-tag-1.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It's OK.
Thank you very much
Hi Luc,
I have 10,000 VMs across 5 linked VCs, I connect using "all-linked" and I want to Get-VM with a particular tag, doing this method seems quiet slow as it has to check each VM and check for that tag, is there any faster way you could think of?
If you know the Tag Category, you could do
Get-TagAssignment -Category Categoryxyz
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
To my last question I figured out another way which works very quickly, takes less than 1 minute now where as before with the other code it was taking 30 minutes.
$VCs = ('vc1', 'vc2', 'vc3', 'vc4', 'vc5')
Foreach ($VC in $VCs) {
Remove-Variable -Name Tag
$Server = Connect-VIServer -Server ($VC + ".vsphere.local") -Credential $vcCreds
Write-Host "Connecting to $VC"
$Tag = Get-Tag -Name VM-TAG-NAME
Get-VM -Tag $Tag
Disconnect-VIServer * -Force -Confirm:$false
}
and If I would like to add the UsedSpace on this command ?
Thanks
LucD
I'm not sure which of the snippets in this thread you are referring to, but via the Entity property, you can access all the VM properties.
where {$_.Tag -like 'tag-1*'} |
Select @{N = 'VM'; E = {$_.Entity.Name}}, @{N = 'UsedSpace'; E = {$_.Entity.UsedSpaceGB}} |
Export-CSV C:\Scripts\result\vms-tag-1.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is by far the fastest way to accomplish the task. 15.5 seconds against 887 tagged vm's. As mentioned by Nicholas1982, processing Get-TagAssignment against Get-VM takes 30+ minutes for large VM environments. What the OP is essentially looking for is all in the Get-TagAssignment cmdlet vs the very robust Get-VM.
This is by far the fastest way to accomplish the task. 15.5 seconds against 887 tagged vm's. As mentioned by Nicholas1982, processing Get-TagAssignment against Get-VM takes 30+ minutes for large VM environments. What the OP is essentially looking for is all in the Get-TagAssignment cmdlet vs the very robust Get-VM.
Works quickly and without issue.
"Get-TagAssignment -Category "ENTER YOUR TAGS CATAGORY NAME" | Select @{N='VM';E={$_.Entity.Name}} | Export-CSV C:\Scripts\result\vms-TAG_NAME.csv -NoTypeInformation"