Al,
If I am understanding the problem, I think the fix should be pretty straightforward.
It looks like you grab what the os should be in $tag, and you grab what the tag currently is in $present
I am not reproducing your whole script, just how I think this would work for you.
$What_OS_Tag_Should_Be = $vm.ExtensionData.Guest.GuestFullName
$Current_OS_Tag = get-tagassignment -category "os" -entity $vm
if ($currentOSTag -notlike $WhatOSTagShouldBe)
{
Get-TagAssignment -Category "os" -entity $vm | Remove-TagAssignment -Confirm:$false
New-TagAssignment -Entity $vm -Tag $WhatOSTagShouldBe -Confirm:$false
}
I don't use tags all the time, but I believe this should work, or be really close for what you want