I'm trying to export a CSV file that has a list of all VM's in a cluster that doesn't have a specific tag I'm using for rightsizing. However, the CSV isn't populating with anything other than this: ÿþ
I'm trying to export a CSV file that has a list of all VM's in a cluster that doesn't have a specific tag I'm using for rightsizing. However, the CSV isn't populating with anything other than this: ÿþ
Get-Module -Name VMware* -ListAvailable | Import-Module -Force
$exportto = "C:\Users\username\Desktop\rightSizingFilter3.csv"
$VMs = Get-Cluster -name clustername | Get-VM
foreach ($VM in $VMs){
If (((Get-Tagassignment $VM).Tag.Name -notcontains "testtag")){
Out-file $exportto -Append
}
}
I got it to work from the snippet below:
$RS = foreach ($VM in $VMs){
If (((Get-Tagassignment $VM).Tag.Name -notcontains "testtag")){
Write-Output $VM
}
}
$RS | Out-file $exportto -Append
Moderator note: Moved to VMware PowerCLI Discussions
I got it to work from the snippet below:
$RS = foreach ($VM in $VMs){
If (((Get-Tagassignment $VM).Tag.Name -notcontains "testtag")){
Write-Output $VM
}
}
$RS | Out-file $exportto -Append
You could do something like this
$exportto = "C:\Users\username\Desktop\rightSizingFilter3.csv"
Get-Cluster -Name clustername |
Get-VM |
Get-TagAssignment |
where{$_.Tag.Name -notmatch 'testtag'} |
Select @{N='VM';E={$_.Entity.Name}},
@{N='Tag';E={$_.Tag.ToString()}} |
Export-Csv -Path $exportto -UseCulture -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@LucDThat works great