VMware Cloud Community
sck1025
Enthusiast
Enthusiast
Jump to solution

Script to show Powered Off VM along with Tag

Can anybody help me out? 

I need script that will show me what tag is assigned to a machine but only on machines that are powered off.

So far I have:

Get-VM |

Select-Object Name, 

@{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}} |

Export-Csv c:\PoweredOffTag.csv

This brings back the tags for all machines I am not sure where to place the "And" so that it queries just powered off VM's.

TIA.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Just add a Where-clause after the Get-VM, something like this.

Get-VM |

where{$_.PowerState -eq 'PoweredOff'} |

Select-Object Name,

@{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}} |

Export-Csv c:\PoweredOffTag.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Just add a Where-clause after the Get-VM, something like this.

Get-VM |

where{$_.PowerState -eq 'PoweredOff'} |

Select-Object Name,

@{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}} |

Export-Csv c:\PoweredOffTag.csv


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sck1025
Enthusiast
Enthusiast
Jump to solution

Perfect, Thanks Luc!

0 Kudos