Hello,
I've taken this Script for Datastore Tags:
Connect-viserver xxxxxxx -user xxxxxxxx -password xxxxxxxx
$CMDBInfo = Import-CSV .\DS-Tag.csv
# Get the header names to use as tag category names
$TagCatNames = $cmdbinfo | Get-Member | Where {$_.MemberType -eq "NoteProperty"} | 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
}
# 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
}
# 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
}
}
}
The csv File looke like this:
Name,Location,StoragePool,Sync
SYNC_LA2_SVC_INFRATIS_VOL_01,LA2,MIXED,JA
SYNC_ARS_SVC_INFRATIS_VOL_01,ARS,MIXED,JA
ARS_SVC_MS-ONLY_VOL_17,ARS,MIXED,NEIN
LA2_SVC_RELEASEMGMT_VOL_01,LA2,MIXED,NEIN
LA2_SVC_RELEASEMGMT_VOL_02,LA2,MIXED,NEIN
LA2_SVC_RELEASEMGMT_VOL_03,LA2,MIXED,NEIN
LA2_SVC_Releasemgmt_Restore-Test,LA2,MIXED,NEIN
The Script generates only the catagory "Location" with the Tags LA2 oder ARS. Then it runs in a loop with no errors. The other catagories and tags are not generated.
What's wrong?
Thank you
Best regards
Andi