Hello,
I wonder if anyone can help with these couple of reports I've been looking at:
1. A csv that lists all VMs like this - VM Name | VMTools version, Power state, Owner Tag (-Category 'Owner Tagging' )
2. I have this PS script that lists VM for certain tags, how would I list VMs with no tags that doesn't contain the words 'owner' or ' BKP'?
$user = 'user123@vsphere.local'
$file = 'C:\vmwarelog\powercli\pwd\pwd.txt'
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, (Get-Content $file | ConvertTo-SecureString)
Connect-VIServer -Server vc.domain.com -Credential $credentials
$tags = @('Owner - Infra','`Owner - Security')
foreach ($tag in $tags) {
Get-VM -Tag $tag | Format-Table -Property Name,MemoryGB,ProvisionedSpaceGB,UsedSpaceGB,NumCPU,CoresPerSocket
}
Thanks
1. You could do something like this
Get-VM | Select Name,
@{N='ToolsVersion';E={$_.Guest.ToolsVersion}},
PowerState,
@{N='Owner';E={(Get-TagAssignment -VM $_ -Category 'Owner Tagging').Tag.Name}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
2. You could do something like this
Get-VM | Get-TagAssignment | where{$_.Tag.Name notmatch 'owner|BKP'}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks,
Script 1 is great, but no tag shows up, if easy could it lists all tags if it can't show any with owner?
I'll test the other script shortly too.
Thanks!
The 2nd snippet should show if there are any VMs with a tag in the "Owner Tagging" category
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think there must be something wrong with my script, is use to work I sure of it.
$user = 'user1@vsphere.local'
$file = 'C:\vmware\powercli\pwd\pwd.txt'
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, (Get-Content $file | ConvertTo-SecureString)
Connect-VIServer -Server vc.domain.com -Credential $credentials
$tags = @('Owner - Hosting','`Owner - InfoSec')
foreach ($tag in $tags) {
Get-VM -Tag $tag | Format-Table -Property Name,MemoryGB,ProvisionedSpaceGB,UsedSpaceGB,NumCPU,CoresPerSocket
}
Error below, it can't be credentials as I've just run another script with the same config for authentication and it worked.
What do you think of this error?
Get-VM : 8/26/2022 12:06:15 PM Get-VM com.vmware.vapi.std.errors.unauthenticated {'messages': [com.vmware.vapi.std.localizable_message {'id': com.vmware.vapi.endpoint.method.authentication.required,
'default_message': Authentication required., 'args': [], 'params': , 'localized':}], 'data': , 'error_type': UNAUTHENTICATED, 'challenge': Basic realm="VAPI endpoint",SIGN
realm=a0c8581f8121c20fc0f654d4965a9981331744f9,service="VAPI endpoint",sts="https://vc.domain.com/sts/STSService/vsphere.local"}
At C:\Scripts\VMware\vms-with-tagsv2.ps1:10 char:1
+ Get-VM -Tag $tag | Format-Table -Property Name,MemoryGB,ProvisionedSp ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], CisException
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Impl.V1.Service.Tagging.Cis.TaggingServiceCisImpl.GetTag.Error,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM
Get-VM : 8/26/2022 12:06:16 PM Get-VM Could not find Tag with name 'Owner - Hosting'.
Are you on vSPhere 6.7?
Are you running the script from a Windows2012R2 machine?
Are you using PSv5.1?
This error has been mentioned many times, but afaik there has neer been a direct explanation and fix.
For some, upgrading their PowerCLI version worked.
For others, an upgrade of PS worked.
If neither does for you, I suggest opening an SR.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
