Now i will admit, i have no idea what i am doing, and probably not the best way of doing it. Here is what i got so far:
CODE
Option Explicit
Dim objShell, objNetwork, ObjGroupDict
Dim drFinance, drFOutlook, drTest
Dim sgFinance, sgFinance2, sgFOutlook, sgFOutlook2, sgTest
Dim shFinance, shFOutlook, shTest
Dim strDomain, strUser, strAdsPath
Set objNetwork = WScript.CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain
strUser = objNetwork.UserName
strAdsPath = strDomain & "\" & strUser
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
'Drive letters
drFinance = "F:"
drFOutlook = "G:"
drTest = "Z:"
'Security Groups
sgFinance = "CFOOrganization - Finance - M"
sgFinance2 = "CFOOrganization - Finance - R"
sgFOutlook = "CFOOrganization - FinanceOutlook - M"
sgFOutlook2 = "CFOOrganization - FinanceOutlook - R"
sgTest = "testdrivemapping"
'Shares:
shFinance = "\\none\data\CFOOrganization\Finance"
shFOutlook = "\\none\data\CFOOrganization\FinanceOutlook"
shTest = "\\none\data"
if isMember(sgTest) then
objNetwork.RemoveNetworkDrive drTest, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shTest
End If
if isMember(sgFinance) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If
if isMember(sgFinance2) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If
if isMember(sgFOutlook) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If
if isMember(sgFOutlook2) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If
'=========================================================================
'FUNCTIONS
'=========================================================================
Set objNetwork = Nothing
Set objShell = Nothing
Wscript.Quit
Function IsMember(sGroup)
Dim oDict, oUser, oGroup, strDNSDomain, objRootLDAP
If IsEmpty(oDict) Then
Set oDict = CreateObject("Scripting.Dictionary")
set strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
oDict.CompareMode = vbTextCompare
'Location in AD: none.ad.none.net/None Domain Users/Standard Accounts/Americas
Set oUser = GetObject("LDAP://cn=Americas, cn=Standard Aaccounts, cn=None Domain users," & strDNSDomain)
For Each oGroup In oUser.Groups
oDict.Add oGroup.Name, "-"
Next
Set oUser = Nothing
End If
End Function
Dim objShell, objNetwork, ObjGroupDict
Dim drFinance, drFOutlook, drTest
Dim sgFinance, sgFinance2, sgFOutlook, sgFOutlook2, sgTest
Dim shFinance, shFOutlook, shTest
Dim strDomain, strUser, strAdsPath
Set objNetwork = WScript.CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain
strUser = objNetwork.UserName
strAdsPath = strDomain & "\" & strUser
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
'Drive letters
drFinance = "F:"
drFOutlook = "G:"
drTest = "Z:"
'Security Groups
sgFinance = "CFOOrganization - Finance - M"
sgFinance2 = "CFOOrganization - Finance - R"
sgFOutlook = "CFOOrganization - FinanceOutlook - M"
sgFOutlook2 = "CFOOrganization - FinanceOutlook - R"
sgTest = "testdrivemapping"
'Shares:
shFinance = "\\none\data\CFOOrganization\Finance"
shFOutlook = "\\none\data\CFOOrganization\FinanceOutlook"
shTest = "\\none\data"
if isMember(sgTest) then
objNetwork.RemoveNetworkDrive drTest, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shTest
End If
if isMember(sgFinance) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If
if isMember(sgFinance2) then
objNetwork.RemoveNetworkDrive drFinance, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFinance
End If
if isMember(sgFOutlook) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If
if isMember(sgFOutlook2) then
objNetwork.RemoveNetworkDrive drFOutlook, 1, true
wscript.Sleep 10000
objNetwork.MapNetworkDrive drTest, shFOutlook
End If
'=========================================================================
'FUNCTIONS
'=========================================================================
Set objNetwork = Nothing
Set objShell = Nothing
Wscript.Quit
Function IsMember(sGroup)
Dim oDict, oUser, oGroup, strDNSDomain, objRootLDAP
If IsEmpty(oDict) Then
Set oDict = CreateObject("Scripting.Dictionary")
set strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
oDict.CompareMode = vbTextCompare
'Location in AD: none.ad.none.net/None Domain Users/Standard Accounts/Americas
Set oUser = GetObject("LDAP://cn=Americas, cn=Standard Aaccounts, cn=None Domain users," & strDNSDomain)
For Each oGroup In oUser.Groups
oDict.Add oGroup.Name, "-"
Next
Set oUser = Nothing
End If
End Function
right now when i run it i get:
C:\mapdrivetest.vbs(74, 3) Microsoft VBScript runtime error: Object required: 'objRootLDAP'
which is this line:
set strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
I just have no idea what i am doing wrong. I am not sure if i am doing this right at all. Can you point me to the right direction?
--Aen
