Try something like this.
Remove the WhatIf switches when you are sure the output is correct.
When you don't want to remove the TagCategories without Tags, remove the last part (starting with Get-TagCategory).
Get-TagAssignment |
ForEach-Object -Process {
$tableUsed += "$($_.Tag.Category)-$($_.Tag.Name)"
}
Get-Tag |
ForEach-Object -Process {
if ($tableUsed -notcontains "$($_.Category)-$($_.Name)") {
Remove-Tag -Tag $_ -Confirm:$false -WhatIf
}
}
Get-TagCategory |
ForEach-Object -Process {
if (-not (Get-Tag -Category $_)) {
Remove-TagCategory -Category $_ -Confirm:$false -WhatIf
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
Remove the WhatIf switches when you are sure the output is correct.
When you don't want to remove the TagCategories without Tags, remove the last part (starting with Get-TagCategory).
Get-TagAssignment |
ForEach-Object -Process {
$tableUsed += "$($_.Tag.Category)-$($_.Tag.Name)"
}
Get-Tag |
ForEach-Object -Process {
if ($tableUsed -notcontains "$($_.Category)-$($_.Name)") {
Remove-Tag -Tag $_ -Confirm:$false -WhatIf
}
}
Get-TagCategory |
ForEach-Object -Process {
if (-not (Get-Tag -Category $_)) {
Remove-TagCategory -Category $_ -Confirm:$false -WhatIf
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference