Home All Groups Group Topic Archive Search About

evaluate OU from login script



Author
12 Aug 2005 3:23 PM
AdminKen
Is there a way to evaluate the OU of a user/computer in a log in script
(.bat or .vbs)? I would like to create a common login script for all my
users instead of having a different script for every OU but I would need the
script to be aware of the container a user is in so that user can have
different drive mappings etc. I am currently using 'ifmember' for
distinctions between security groups but I would like to also use OUs.

thanks
Ken

Author
12 Aug 2005 5:00 PM
Dominic Johnson
Ken,

you could try something like this in VBScript:

  Set objADInfo = WScript.CreateObject("ADSystemInfo")
  Wscript.Echo objADInfo.UserName

This will give you the distinguished name of the user.
You can extract the lowest OU level from the DN with this


  strStart = InStr(objADInfo.UserName,",OU") + 4

  If strStart = 4 Then

    strStart = Instr(objADInfo.UserName,",") + 4
    strEnd   = Instr(objADInfo.UserName,"DC") -1

  Else

    strEnd   = Instr(strStart,objADInfo.UserName,",")

  End If

  strOU = Mid(objADInfo.UserName,strStart,(strEnd-strStart))

  WScript.Echo strOU


I have used this to get the OU of a computer account in the past
(hence the check to see if "OU" is in the DN string).

It still seems a bit clunky to me but hopefully someone has
a more elegant solution

Dominic
Author
13 Aug 2005 1:07 AM
Paul Bergson
You should be able to find plenty of examples here.

http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx

--

Paul Bergson  MCT, MCSE, MCSA, CNE, CNA, CCA

This posting is provided "AS IS" with no warranties, and confers no rights.


Show quote
"AdminKen" <s***@microsoft.com> wrote in message
news:%23boqVH1nFHA.3312@tk2msftngp13.phx.gbl...
> Is there a way to evaluate the OU of a user/computer in a log in script
> (.bat or .vbs)? I would like to create a common login script for all my
> users instead of having a different script for every OU but I would need
the
> script to be aware of the container a user is in so that user can have
> different drive mappings etc. I am currently using 'ifmember' for
> distinctions between security groups but I would like to also use OUs.
>
> thanks
> Ken
>
>
>
Author
13 Aug 2005 3:34 PM
Torgeir Bakken (MVP)
AdminKen wrote:

> Is there a way to evaluate the OU of a user/computer in a log in script
> (.bat or .vbs)? I would like to create a common login script for all my
> users instead of having a different script for every OU but I would need the
> script to be aware of the container a user is in so that user can have
> different drive mappings etc. I am currently using 'ifmember' for
> distinctions between security groups but I would like to also use OUs.
>
Hi,

VBScript solution:

'--------------------8<----------------------
Set oADSystemInfo = CreateObject("ADSystemInfo")

Wscript.Echo "User's distinguished name: " & oADSystemInfo.UserName

Set oUser = GetObject("LDAP://" & oADSystemInfo.UserName)
Wscript.Echo "User object's parent path: " & oUser.Parent

sOUPathUser = Mid(oUser.Parent, 8)
Wscript.Echo "sOUPathUser is: " & sOUPathUser


Wscript.Echo "Computers's distinguished name: " & oADSystemInfo.ComputerName

Set oComputer = GetObject("LDAP://" & oADSystemInfo.ComputerName)
Wscript.Echo "Computer object's parent path: " & oComputer.Parent

sOUPathComputer = Mid(oComputer.Parent, 8)
Wscript.Echo "sOUPathComputer is: " & sOUPathComputer

'--------------------8<----------------------





--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Author
7 Sep 2005 5:57 AM
AdminKen
Thanks so much.  I will test that.

Show quote
"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:%23TfvTzBoFHA.764@TK2MSFTNGP14.phx.gbl...
> AdminKen wrote:
>
>> Is there a way to evaluate the OU of a user/computer in a log in script
>> (.bat or .vbs)? I would like to create a common login script for all my
>> users instead of having a different script for every OU but I would need
>> the script to be aware of the container a user is in so that user can
>> have different drive mappings etc. I am currently using 'ifmember' for
>> distinctions between security groups but I would like to also use OUs.
>>
> Hi,
>
> VBScript solution:
>
> '--------------------8<----------------------
> Set oADSystemInfo = CreateObject("ADSystemInfo")
>
> Wscript.Echo "User's distinguished name: " & oADSystemInfo.UserName
>
> Set oUser = GetObject("LDAP://" & oADSystemInfo.UserName)
> Wscript.Echo "User object's parent path: " & oUser.Parent
>
> sOUPathUser = Mid(oUser.Parent, 8)
> Wscript.Echo "sOUPathUser is: " & sOUPathUser
>
>
> Wscript.Echo "Computers's distinguished name: " &
> oADSystemInfo.ComputerName
>
> Set oComputer = GetObject("LDAP://" & oADSystemInfo.ComputerName)
> Wscript.Echo "Computer object's parent path: " & oComputer.Parent
>
> sOUPathComputer = Mid(oComputer.Parent, 8)
> Wscript.Echo "sOUPathComputer is: " & sOUPathComputer
>
> '--------------------8<----------------------
>
>
>
>
>
> --
> torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of
> the 1328 page Scripting Guide:
> http://www.microsoft.com/technet/scriptcenter/default.mspx

AddThis Social Bookmark Button