Monday, April 29, 2019

Power shell and .vbs to get machine OU details from AD



You can get the machine name OU Details from using below command and VB script

Power-Shell

([adsisearcher]"(&(name=$env:computername)(objectClass=computer))").findall().path





VB Script (save below command in.vbs Fotomat)

########################################################################

On Error Resume Next

Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName

Set objADSysInfo = CreateObject("ADSystemInfo")
strComputerName = objADSysInfo.ComputerName

Set objComputer = GetObject("LDAP://" & strComputerName)
strOUName = objComputer.DistinguishedName
strOUs = Split(strOUName, ",")
MsgBox strOUs(2)
MsgBox strOUs(1)
strOU = Split(strOUs(2), "=")

#######################################################################


No comments:

Post a Comment