vespavbb
Enthusiast
Enthusiast

get all vms but with exception from import list

Jump to solution

Hi,

I´m struggling with a simple question here.

I want to get all VM ´s but with an exception of some VM´s from a List which comes from a simple txt file.

If I do it like here, the output is twice or more, it depands how many objects are in the txt file. So the loop is wrong, or is there are smarter way? I guess so... Thanks

$excludeVM = Get-Content 'C:\test\exclude.txt' 
$includeVM =  foreach ($vm in $excludeVM) {get-cluster Cluster01 | get-vm | where {$_.Name -notlike $vm }  | Sort-Object -Property name } -Unique
$includeVM

 

VCP4,VCP5,VCP6
0 Kudos
2 Solutions

Accepted Solutions
LucD
Leadership
Leadership

You could do something like this

 

$excludeVM = Get-Content 'C:\test\exclude.txt' 
$includeVM = Get-Cluster | Get-VM | where{$excludeVM -notcontains $_.Name} | Sort-Object -Property Name
$includeVM

 

 


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

View solution in original post

LucD
Leadership
Leadership

Something like this


 

$tag = Get-Tag -Name 'ignore' -Category 'exception'
Get-Cluster | Get-VM | where{ (Get-TagAssignment -Entity $_).Tag.Id -notcontains $tag.Id}

 




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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

You could do something like this

 

$excludeVM = Get-Content 'C:\test\exclude.txt' 
$includeVM = Get-Cluster | Get-VM | where{$excludeVM -notcontains $_.Name} | Sort-Object -Property Name
$includeVM

 

 


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

View solution in original post

vespavbb
Enthusiast
Enthusiast

Thank you, thant works for me,

 

how would you do the exception thing with tag´s on VM´s

Exclude VM´s where  Tag -like "ignore*" in category "exception"

VCP4,VCP5,VCP6
0 Kudos
LucD
Leadership
Leadership

Something like this


 

$tag = Get-Tag -Name 'ignore' -Category 'exception'
Get-Cluster | Get-VM | where{ (Get-TagAssignment -Entity $_).Tag.Id -notcontains $tag.Id}

 




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

View solution in original post

0 Kudos