Reply to Message

View discussion in a popup

Replying to:
jmarkey
Contributor
Contributor

Hi LucD-

Thank you for the  help!  I added the line, but unfortunately I am still getting results that are in different order on each VM.  I don't know what I am missing.  

# Get the header names to use as tag category names

$TagCatNames = $cmdbinfo | Get-Member | Where {$_.MemberType -eq "NoteProperty"} | Sort-Object -Property Name | Select -Expand Name

# Create the Tag Category if it doesnt exist

Foreach ($Name in ($TagCatNames | Where {$_ -ne "Name"})) {

Try {

$tCat = Get-TagCategory $Name -ErrorAction Stop

}

Catch {

Write-Host "Creating Tag Category $Name"

$tCat = New-TagCategory -Name $Name -Description "$Name from CMDB"

}


# Create Tags under the Tag Categories

$UniqueTags = $cmdbinfo | Select -expand $Name | Get-Unique

Foreach ($Tag in $UniqueTags) {

Try {

$tTag = Get-Tag $Tag -Category $tCat -ErrorAction Stop

}

Catch {

Write-Host "..Creating Tag under $Name of $Tag"

$tTag = New-Tag -Name $Tag -Category $tCat -Description "$Tag from CMDB"

}


# Assign the Tags to the VMs/Hosts

$cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {

Write-Host ".... Assigning $Tag in Category of $Name to $($_.Name)"

New-TagAssignment -Entity $($_.Name) -Tag $tTag | Out-Null

}

}

}

Reply
0 Kudos