sck1025
Enthusiast
Enthusiast

Script to show Powered Off VM along with Tag

Jump to solution

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

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

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

Perfect, Thanks Luc!

0 Kudos