This line...

$OU = GetObject("LDAP://"+CreateObject("ADSystemInfo").ComputerName).Parent

is returning the OU in a format like so...

LDAP://OU=Terminal Servers,OU=Servers,OU=Computers,OU=Headquarters,DC=domain,DC=domain,DC=com

It's just a matter of manipulating that string to get the level that you want, and then comparing that to something in your script.