Jump to content

Recommended Posts

Posted
In the past I've created a different background for staff and pupils to easily identify different users when they log on. What I want to do now is get the location for each computer as we have had some jobs which look like the GPO are not applying properly. I was going to do this by creating a new image for each room with the room name embedded in but thought as we are also using BGInfo could we get the OU information through that? I can't see an obvious setting but thought maybe through a WMI filter?
Posted

Host Name gives you the computer name - isn't that enough to locate the computer?

If not, and you really want the information from AD then you'll have to write a script for that.

There's a nice little script here that will popup the OU

 


OPTION EXPLICIT
DIM objNetwork
DIM computerName
DIM ou


' Get the computerName of PC
SET objNetwork = CREATEOBJECT("Wscript.Network")
computerName = objNetwork.ComputerName


' Call function to find OU from computer name
ou = getOUByComputerName(computerName)


' Echo ou
wscript.echo ou



FUNCTION getOUByComputerName(BYVAL computerName)
' *** Function to find ou/container of computer object from computer name ***
DIM namingContext, ldapFilter, ou
DIM cn, cmd, rs
DIM objRootDSE
' Bind to the RootDSE to get the default naming context for
' the domain.  e.g. dc=wisesoft,dc=co,dc=uk
SET objRootDSE = GETOBJECT("LDAP://RootDSE")
namingContext = objRootDSE.GET("defaultNamingContext")
SET objRootDSE = NOTHING


' Construct an ldap filter to search for a computer object
' anywhere in the domain with a name of the value specified.
ldapFilter = "  ">;(&(objectCategory=Computer)(name=" & computerName & "))" & _
";distinguishedName;subtree"


' Standard ADO code to query database
SET cn = CREATEOBJECT("ADODB.Connection")
SET cmd = CREATEOBJECT("ADODB.Command")


cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn
cmd.commandtext = ldapFilter
SET rs = cmd.EXECUTE


IF rs.eof <> TRUE AND rs.bof <> TRUE THEN
ou = rs(0)
' Convert distinguished name into OU.
' e.g. cn=CLIENT01,OU=WiseSoft_Computers,dc=wisesoft,dc=co,dc=uk
' to: OU=WiseSoft_Computers,dc=wisesoft,dc=co,dc=uk
'wscript.echo "first ou:" & ou
'ou = MID(ou,INSTR(ou,",")+1,LEN(ou)-INSTR(ou,","))
ou = MID(ou,INSTR(ou,"OU"),INSTR(ou,"DC")-INSTR(ou,"OU"))
getOUByComputerName = ou


END IF


rs.close
cn.close


END FUNCTION

I found it here:

Show PC AD OU Membership - Sysinternals Forums

  • Thanks 1
Posted

The reason I want the OU is I want to display the room so we know that the computer is getting the correct settings when logging on. It is fairly easy for the end user to see that there is Library written on the desktop but they are sitting in an Maths room. The idea is that it is easier to see if something is not right without having to find where the computer is in AD.

 

I'll take a look at the script you posted but it may be easier to just generate separate background images than testing through scripts as I already have what we need for BGInfo (except OU)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...