Page 1 of 1
Help with Logon Script
Posted: September 21, 2006, 3:12 pm
by Bubba Grizz
I need to create a script for a class I am in and need to know if this code will work. What pitfalls I may encounter and other such nonsense.
Code: Select all
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
For Each strGroup in objUser.MemberOf
strGroupPath = "LDAP://" & strGroup
Set objGroup = GetObject(strGroupPath)
strGroupName = objGroup.CN
Select Case strGroupName
Case "Sales_Group"
objNetwork.MapNetworkDrive "S:", "\\server\public\Sales"
Case "HR_Group"
objNetwork.MapNetworkDrive "H:", "\\server\public\HR"
Case "IT_Group"
objNetwork.MapNetworkDrive "I:", "\\server\public\IT"
Case "Purchasing_Group"
objNetwork.MapNetworkDrive "P:", "\\sever\public\Purchasing"
Case "Accounting_Group"
objNetwork.MapNetworkDrive "T:", "\\server\public\Accounting"
End Select
Next
Posted: September 21, 2006, 5:01 pm
by cadalano
you might want to verify that they dont already have maps to those drive letters.
you can also skip going through the AD group object by just searching for "CN=<group>" in your AD memberOf result set which will save time if you have a lot of AD groups in use. For example, if I run your script at my work it takes it about 45 seconds to finish, even without actually mapping any drives. Our logon script looks more like this though, which completes in about 2 seconds:
On Error Resume Next
Dim strSeek
Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)
Sub mapGroups()
For Each strGroup in objUser.MemberOf
strSeek = strSeek & strGroup
Next
'alter aGroups' dimensions to correspond with the items below when changes are made
Dim aGroups (4)
'delimiter is a comma
aGroups(0)="Sales_Group,S:,\\server\public\Sales"
aGroups(1)="HR_Group,H:,\\server\public\HR"
aGroups(2)="IT_Group,I:,\\server\public\IT"
aGroups(3)="Purchasing_Group,P:,\\sever\public\Purchasing"
aGroups(4)="Accounting_Group,T:,\\server\public\Accounting"
For each groupString in aGroups
aGroupSplit = Split(groupString, ",")
seekGroup aGroupSplit(0), aGroupSplit(1), aGroupSplit(2)
Next
End sub
Sub seekGroup(seekGroupName, seekGroupLetter, seekGroupNetPath)
If inStr(1, strSeek, "CN=" & seekGroupname)>0 Then
'verify drive letter is not in use
Set aEnumDrives = objNetwork.EnumNetworkDrives
For i = 0 to aEnumDrives.Count - 1 Step 2
If aEnumDrives.Item(i) = seekGroupLetter Then
exit sub
End If
Next
objNetwork.MapNetworkDrive seekGroupLetter, seekGroupNetPath
End If
End Sub
call mapGroups()
probably overkill for a class.. but hey
Posted: September 21, 2006, 10:06 pm
by Bubba Grizz
yeah this is for a lab that has only 5 OU's and maybe 30 people. We are learning about importing and exporting AD stuff using CSVDE. All the users are part of one group and not many so I don't need to worry about them getting a different drive.
Thanks for the response.
Posted: October 31, 2006, 4:32 pm
by Sylvus
Someone at work was looking for help on this, and I know nothing of AD and little of VBS. If this makes sense to anyone and you have any ideas, it'd be appreciated.
Basically he's trying to figure out how to find the associated AD user once he has an Exchange user. Or somesuch.
Good morning. I was looking at a few vbs scripts I had for exchange space usage reports, and I can get the following easily:
Server StorageGroup MailStore User Size(KB) TotalItems
EG-CSIMSGQA-B1A First Storage Group Mailbox Store (EG-CSIMSGQA-B1A) SQLservice 76 36
EG-CSIMSGQA-B1A First Storage Group Mailbox Store (EG-CSIMSGQA-B1A) Administrator 46 30
EG-CSIMSGQA-B1A First Storage Group Mailbox Store (EG-CSIMSGQA-B1A) TESt 66 17
EG-CSIMSGQA-B1A First Storage Group Mailbox Store (EG-CSIMSGQA-B1A) TEST2 0 0
My only issue right now is getting the associated AD User account the the MailBox DisplayName which is the property displayed in the "User" column. Do you know of an easy way to find the associated AD User?
Here is a sample of a script:
Dim SWBemlocator
Dim objWMIService
Dim colItems
Dim objFSO
Dim objFile
strTitle="Mailbox Report"
strComputer ="EG-CSIMSGQA-B1A"
UserName = "(User Name with admin rights to Exchange)"
Password = "(password)"
strLog="c:\temp\MailboxReport.csv"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objFile=objFSO.CreateTextFile(strLog,True)
strQuery="Select * from Exchange_Mailbox"
objFile.WriteLine "Server,StorageGroup,MailStore,User,Size(KB),TotalItems"
WScript.Echo "Examining " & strComputer
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = SWBemlocator.ConnectServer(strComputer,_
"\root\MicrosoftExchangeV2",UserName,Password)
Set colItems = objWMIService.ExecQuery(strQuery,,48)
For Each objItem in colItems
objFile.writeline objItem.ServerName & "," &objItem.StorageGroupName &_
"," & objItem.StoreName & "," & Chr(34) & objItem.MailboxDisplayName &_
Chr(34) & "," & objItem.Size & "," & objItem.TotalItems
Next
objFile.close
WScript.Echo "See " & strLog & " for results."