#191812 - 2009-01-15 08:10 PM
create directory structure for users and ou structures
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
I have not started on this yet. I am just checking to see if I will not be reinventing the wheel. Does anyone have a script that would read and convert OU Structure \OU1\OU2\User1
to
Dir Path structure C:\OU1\OU2\User2
|
|
Top
|
|
|
|
#191834 - 2009-01-19 04:53 PM
Re: create directory structure for users and ou structures
[Re: Richard H.]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
This is basicly creating home ares for users, but we want it to mimic the OU structure to a directory structure.
This needs to be done for all sub-OUs of a single OU. I already have the rights and share commands to be executed.
Edited by coder (2009-01-19 04:56 PM)
|
|
Top
|
|
|
|
#191838 - 2009-01-19 06:32 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
I am not very skilled in creating LDAP queries tho. I can place what I have so far.
Dim $aAttributes,$sADsPath,$strFilter
Dim $aResults,$c,$r
$aAttributes = "DN"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectCategory=person)(objectClass=user))"
$aResults = fnLDAPQuery($aAttributes,$sADsPath,$strFilter)
For Each $r in $aResults
If InStr($r,"=")
Split($r,"=")[Ubound(Split($r,"="))]
Else
$r ?
EndIf
Next
This is returning no results.
|
|
Top
|
|
|
|
#191841 - 2009-01-19 08:54 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
This little browser from Chris S. should do the trick as well and you can review the code to see how it works as well.
Requires KiXforms from Shawn Tassie KiXforms
KiXforms - Active Directory Browser Version 2
|
|
Top
|
|
|
|
#191844 - 2009-01-19 09:34 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
I have slightly modified what I had. The problem I am having now is trying to set ADPath to a Dir Path structure.
Here is the modified code:
Dim $aAttributes,$sADsPath,$strFilter
Dim $aUsers,$sUser
$RootPath = "D:\HomeFolderTest\"
$aAttributes = "samAccountName", "AdsPath"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectClass=User)(Name=*))"
$aUsers = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
? @ERROR " | " @SERROR " when running User Query"
; Ensuring Directories exist
For $c = 0 to Ubound($aUsers)
$DestDir = $RootPath + $aUsers[$c,1]
? "("+$c+")Checking Dir " + $DestDir
; If dir does not exist create it.
Next
The $DestDir is what I am looking at now. Currently it is still raw in the Distinguished type format.
|
|
Top
|
|
|
|
#191853 - 2009-01-20 08:03 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
here is the current version of this file. I am getting an error saying that I am missing a ")" on line 24(The IofSubStr line). But I just cant see it. Can someone see anything I don't in here?
call @Scriptdir + "\ADUtils.udf"
call @Scriptdir + "String.udf"
$output = RedirectOutput("C:\LDAPOutput.txt")
Dim $aAttributes,$sADsPath,$strFilter
Dim $aUsers,$sUser
$RootPath = "E:\HomeFolderTest"
$aAttributes = "samAccountName", "AdsPath"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectClass=User)(objectClass=person)(Name=*))"
$aUsers = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
;? @ERROR " | " @SERROR " when running User Query"
; Ensuring Directories exist
For $c = 0 to Ubound($aUsers)
$sDestDir = $RootPath + $aUsers[$c,1]
$ar_DN = Split($sDestDir,",")
For each $element in $ar_DN
$dir = $dir + "\" + Split($Element,"=")[1]
$sDestDir = $RootPath + $Dir
If Not (Left($Dir,4)= "\PFS")
$sRmv = "\OU3\OU2\OU3"
$Location = IofSubStr($sDestDir,$sRmv,1)
$sDestDir = SubStr($sDestDir, 0,$Location) + SubStr($sDestDir, $Location + Len(sRmv), Len $sDestDir)
? "Create " + $sDestDir
; fnCreateHomeFolder($sDestDir)
Else
? "Skipping Check for " + $Dir
EndIf
; EndIf
Next
Next
sleep 30
$output = RedirectOutput("")
Function fnCreateHomeFolder($Dir)
if exist("$Dir")=0
md "$Dir"
if @error=0
? "Home Folder created at $Dir"
else
? "Home Folder was NOT created at $Dir"
endif
endif
EndFunction
|
|
Top
|
|
|
|
#191855 - 2009-01-20 08:31 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
IofSubStr is a function I found on the Kix boards created by Lonkero.
IofSubStr
|
|
Top
|
|
|
|
#191857 - 2009-01-20 08:39 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
coder
Fresh Scripter
Registered: 2009-01-14
Posts: 39
|
That is the one I called. I have it in String.udf (since it is related to string processing).
It cant figure where the error is coming from though.
|
|
Top
|
|
|
|
#191867 - 2009-01-21 02:33 PM
Re: create directory structure for users and ou structures
[Re: Gargoyle]
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
I'm not too sure exactly what you are trying to do, but this example constructs a path from the OU structure (requires fnLDAPQuery() UDF):
Break ON
$=SetOption("Explicit","ON")
Dim $aAttributes,$sADsPath,$strFilter
Dim $aUsers,$iIndex,$sPath,$aOUs,$sElement,$sDSN
$aAttributes = "samAccountName", "AdsPath"
$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")
$strFilter = "(&(objectClass=User)(objectClass=person)(Name=*))"
$aUsers = fnLDAPQuery($aAttributes,$sADsPath,$strFilter,"Name")
; Ensuring Directories exist
For $iIndex=0 To UBound($aUsers)
$sDSN=$aUsers[$iIndex,1]
; First drop the providor and CN information
$sDSN=SubStr($sDSN,InStr($sDSN,",OU=")+4)
; Now drop the domain information
$sDSN=SubStr($sDSN,1,InStr($sDSN,",DC=")-1)
; Finally, split the OU parts out
$aOUs=Split($sDSN,",OU=")
; Now create the path
$sPath=""
For Each $sElement in $aOUs
$sPath="\"+$sElement+$sPath
Next
"Path for "+$aUsers[$iIndex,0]+"="+$sPath ?
Next
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|