2014-04-21 5 views
0

포함 된 OU에서 사용자를 찾는 하위 루틴을 호출하여 작동하도록 다음 로그온 스크립트를 얻으려고합니다. 그러면 드라이브 매핑이 하위 루틴 내에서 수행됩니다 그룹을 만들지 않고 그룹을 만들지 않고 대기업의 각 OU에 대해 도메인 사용자를 유지 관리하는 대신 OU 당 도메인 사용자를 사용하기를 원하므로 그룹 단위로 OU를 필터링하는 것이 훨씬 쉽습니다. 첫 번째 수준. 나는이 일을 얻을 수 없지만 어떤 도움을 주시면 대단히 감사하겠습니다. 나는이 긴 지나치게 바람이 스크립트를 폐기 결국 내가 정말 일할 수있는 전술 스크립트를 원하지만, 더 쉽게 반복 서브 루틴에서 뭔가 갔다Logon VBS를 사용하여 OU 및 그룹을 통해 드라이브 매핑

On Error Resume Next 
Dim objfileserverO,objFILE,objShell,objNetwork 
set objfileserverO=CreateObject("Scripting.FileSystemObject") 
set objShell=CreateObject("Wscript.Shell") 
set objNetwork=CreateObject("Wscript.Network") 
set objSysInfo = CreateObject("ADSystemInfo") 



strUserDN = objSysInfo.UserName 

Set objUser = GetObject("LDAP://" & strUserDN) 

strOUPath = objUser.Parent 

Function GetUserOU(strOUPath) 
Select Case strOUPath 
Case "LDAP://ou=Users,ou=abzed,ou=domain,dc=domain,dc=org" 
    Call MapIt1 
Case "LDAP://ou=Users,ou=huston,ou=domain,dc=domain,dc=org" 
    Call MapIt2 
Case "LDAP://ou=Users,ou=denv,ou=IEB,ou=domain,dc=domain,dc=org" 
    Call MapIt3 
Case "LDAP://ou=Users,ou=huston,ou=IEB,ou=domain,dc=domain,dc=org" 
    Call MapIt4 
Case "LDAP://ou=Users,ou=lafa,ou=IEB,ou=domain,dc=domain,dc=org" 
    Call MapIt5 
Case "LDAP://ou=Users,ou=NEW,ou=IEB,ou=domain,dc=domain,dc=org" 
    Call MapIt6 
End Select 
End Function 

Function IsAMemberOf(strDomain,strUser,strGroup) 
On Error Resume Next 
Set objUser=GetObject("WinNT://" & strDomain & "/" & strUser & ",user") 
Set objGrp=GetObject("WinNT://" & strDomain & "/" & strGroup & ",group") 

If objGrp.IsMember(objUser.ADsPath) Then 
IsAMemberOf=True 
Else 
IsAMemberOf=False 
End If 

End Function 


Sub MapIt1(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"OG_SystemsIntegration") Then  MapIt1 "K:","\\domain-fileserver2.domaingroup.com\Shared\SI" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"OG_BidsPropsals") Then MapIt1 "L:","\\domain-fileserver2.domaingroup.com\Shared\BIDS" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"OG_BidsGuest") Then MapIt1 "L:","\\domain-fileserver2.domaingroup.com\Shared\BIDS" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_SALES") Then MapIt1 "N:","\\domain-fileserver2.domaingroup.com\shared\sales" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"OG_Operations") Then MapIt1 "O:","\\domain-fileserver2.domaingroup.com\shared\Operations" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_Stores") Then MapIt1 "Q:","\\domain-fileserver2.domaingroup.com\shared\stores" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_Accounts") Then MapIt1 "S:","\\domain-fileserver2.domaingroup.com\shared\accounts" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_IT") Then MapIt1 "T:","\\domain-fileserver2.domaingroup.com\shared\IT" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_MIS") Then MapIt1 "V:","\\domain-fileserver2.domaingroup.com\shared\MIS" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_Archive") Then MapIt1 "W:","\\domain-fileserver2.domaingroup.com\Archive" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_INTRANET") Then MapIt1 "X:","\\domain-fileserver2.domaingroup.com\shared\intranet" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"SUP_BUSINESS") Then MapIt1 "Y:","\\domain-fileserver2.domaingroup.com\shared\Business" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt1 "P:","\\domain-fileserver2.domaingroup.com\products" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt1 "U:","\\domain-fileserver2.domaingroup.com\companyinfo" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt1 "Z:","\\domain-fileserver2.domaingroup.com\Shared\scratchpad" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"UK Engineers") Then MapIt1 "I:","\\domain.Org\shared" 
End If 
End Sub 


Sub MapIt2(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain User") Then MapIt2 "I:","\\domain.Org\shared" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"domain Leadership Team_Agings") Then MapIt2 "M:","\\domain.org\shared\Leadership Team" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"domain International Tax") Then MapIt2 "L:","\\domain.org\shared\Tax\" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"domain_NO") Then MapIt2 "V:","\\fileserver01\visma" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"abzedserver") Then MapIt2 "Q:","\\server1\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Site server5 Groups") Then MapIt2 "R:","\\server1\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"abzedserver") Then MapIt2 "S:","\\server\" 
End If 
End Sub 


Sub MapIt3(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt3 "G:","\\server2\apps" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt3 "P:","\\server2\public" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt3 "U:","\\server2\users" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt3 "X:","\\server2\groups" 
End If 
End Sub 


Sub MapIt4(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt4 "X:","\\server5" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt4 "L:","\\server4\applications" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Group 3 - r") Then MapIt4 "Y:","\\server3\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Group 3 - rw") Then MapIt4 "Y:","\\server3\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"System Maintenance - r") Then MapIt4 "Z:","\\server3\groups\System Maintenance" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"System Maintenance - rw") Then MapIt4 "Z:","\\server3\groups\System Maintenance" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Marketing") Then MapIt4 "I:","\\domain.org\shared" 
End If 
End Sub 


Sub MapIt5(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt5 "I:","\\fileserver1\Sites" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Procurement and Logistics") Then MapIt "S:","\\domain.org\shared" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt5 "V:","\\fileserver1\PRIV_" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt5 "L:","\\fileserver1\applications" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt5 "P:","\\campappfileserver1\StvPFILE" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt5 "H:","\\fileserver1\rti4" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Tier III - r") Then MapIt5 "Y:","\\server3\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Tier III - rw") Then MapIt5 "Y:","\\server3\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"System Maintenance - r") Then MapIt5 "Z:","\\server3\groups\System Maintenance" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"System Maintenance - rw") Then MapIt5 "Z:","\\server3\groups\System Maintenance" 
End If 
End Sub 


Sub MapIt6(strDrive,strMap) 
On Error Resume Next 
If objfileserverO.DriveExists(strDrive) Then objNetwork.RemoveNetworkDrive(strDrive) 

objNetwork.MapNetworkDrive strDrive,strMap 

If Err.Number<>0 And blnShowError Then 
strMsg="There was a problem mapping drive " & UCase(strDrive) & " to " &_ 
strMap & VbCrLf & strHelpMsg & VbCrLf & "Error#:" & Hex(err.Number) &_ 
VbCrLf & Err.Description 
objShell.Popup strMsg,iErrorTimeOut,"Error",vbOKOnly+vbExclamation 
Err.Clear 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt6 "Y:","\\server3\groups" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt6 "M:","\\server3\users" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt6 "X:","\\server3\apps" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt6 "L:","\\fileserver1\applications" 
If IsAMemberOf(objNetwork.UserDomain,objNetwork.UserName,"Domain Users") Then MapIt6 "Z:","\\server3\groups\System Maintenance" 
End If 
End Sub 

답변

0

... 내가 아주 가까이 느낀다.

Set objSysInfo = CreateObject("ADSystemInfo") 


strUser = objSysInfo.UserName 
Set objUser = GetObject("LDAP://" & strUser) 

strUserName = objUser.samAccountName 

strOUPath = objUser.Parent 
arrContainers = Split(strOUPath, ",") 
arrOU = Split(arrContainers(0), "=") 
strOU = arrOU(1) 

If arrOU(1) = "OU=test2,OU=test1,OU=TestOU,DC=domain,DC=com" Then 
strDrive = "\\sharename\share\share" 
Set objNetwork = CreateObject("Wscript.Network") 
objNetwork.MapNetworkDrive "Z:", strDrive 
End If