Reply to Message

View discussion in a popup

Replying to:
No_Way
Enthusiast
Enthusiast

Hi Zik


Thanks for your reply.

Your reply did put me on the right track and had some ideas how to do it

This is what I have until now

$vms = Get-Cluster "Cluster test" | Get-VM

Foreach($vm in $vms) {

    $vmview = $vm | get-view

    If

        ($vmview.Summary.Config.GuestFullName -like "*Windows*") {

        Write-Host "VM Name: " $vm  "Windows VM"

        #New-TagAssignment –Tag "Windows"

        }

       

    elseif

        ($vmview.Summary.Config.GuestFullName -like "*Linux*"){

        Write-Host "VM Name: " $vm " Linux VM"}

        #New-TagAssignment –Tag "Linux"

       

    elseif

        ($vmview.Summary.Config.GuestFullName -like "*CentOS*"){

        Write-Host "VM Name: " $vm " Linux/CentOS VM"}

   

    else {Write-Host "No Changes "}

Now I am struggling to check if a specific TAG is already created, if not it will creates.

Still testing:

Foreach($Tags in $Tag) {

if ($Tags.Name -notlike "*Linux*" )

{

Write-Host "No TAG Founded"

New-Tag –Name "Linux" -Description "VMs System Operation TAG" –Cardinality single –EntityType VirtualMachine

Write-Host "Tag Linux Added" | Select $tags.Name

}

else {Write-Host "TAG"}

}

But I discover that New-Tag and New-TagCategory works in different PowerCli versions.

Reply
0 Kudos