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
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
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
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
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"
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