Just some quick code to get the OU Name of the computer we run the script on.
VBS:
vbnet
Download
Function GetComputerOU
Dim objSysInfo: Set objSysInfo = CreateObject("ADSystemInfo")
Dim objComputer: Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
Dim objOU : Set objOU = GetObject(objComputer.Parent)
GetComputerOU = objOU.OU
End Function
Wscript.Echo GetComputerOUPowerShell:
powershell
Download
function GetComputerOU
{
$SysInfo = New-Object -ComObject "ADSystemInfo"
$Computer = [ADSI]("LDAP://{0}" -f $SysInfo.GetType().InvokeMember("ComputerName", [System.Reflection.BindingFlags]::GetProperty, $null, $SysInfo, $null))
return ([ADSI]$Computer.Parent).OU
}
GetComputerOU