Quote:
|
Why not just edit SQL directly and change the policyID ?
|
because you shouldn't be editing users at the database level.
in any event i think i may have figured it out. it could probably be done a lot better but it works for me. it queries AD to see if the smtp address exists, then finds the user on the bes, if they are found, it will take the bes they are on and set their policy. you need to specify your AD server at the top, your ad path about a quarter of the way down and some of the BRK commands twice towards the bottom.
put into a txt file called users2enable.txt SMTP addresses, one per line.
------------------------------------------------------------
'On Error Resume Next
Const ADS_UF_ACCOUNTDISABLE = 2
'quit if using wscript
strScriptHost = LCase(Wscript.FullName)
If Right(strScriptHost, 11) = "wscript.exe" Then
Wscript.Echo "You must run this script from cscript."
Wscript.Quit
End if
varinputfile = ".\users2enable.txt" 'file should a be a listing of users SMTP addresses 1 per line
strDC = "ACTIVE DIRECTORY SERVER TO QUERY" 'AD server to query
'file to log the output to
strLogPath = ".\BesPolicy Change-" & Month(Now) & "." & Day(Now) & "." & Year(Now) & "-" & Hour(Now) & "."& Minute(Now) & "." & Second(Now) & ".xls"
Set objFSO = CreateObject("Scripting.FileSystemObject")
'check for BESUserAdminClient.exe
Set strBESUAC = objFSO.GetFile("./BESUserAdminClient.exe")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' error code if the file isn't there
If Err <> 0 Then
Wscript.Echo "BESUserAdminClient.exe not found"
WScript.Quit
End If
Set File = objFSO.GetFile(varInputFile)
' error code if the file isn't there
If Err <> 0 Then
Wscript.echo "Data file not found - " & varInputFile
WScript.Quit
End If
' open the file to be read
Set TextStream = File.OpenAsTextStream(1)
'read in each line
i=0
wscript.echo "reading in " & varInputFile
Do While Not TextStream.AtEndOfStream
' creates an array variable for each line. first line is array(0) not array(1)
ReDim Preserve arylines(i)
arylines(i) = Trim(TextStream.ReadLine)
'wscript.echo arylines(i)
' increase the line number
i = i + 1
Loop
' close file
TextStream.Close
objFSO = ""
wscript.echo " Opening the log file - " & strLogPath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strLogPath, 2, True, 0)
If Err.Number <> 0 Then
On Error GoTo 0
WScript.Echo "File " & strLogPath & " cannot be opened"
Set objFSO = Nothing
WScript.Quit
End If
'Write column headers for output file
objFile.Writeline "Primary SMTP Address Status"
'Setup connections To AD
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
'Create Commands
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.properties("Page size") = 100000
objCommand.Properties("Cache Results") = True
For Each strSMTP In arylines
intRowCounter = intRowCounter + 1
' Retrieve Distinguished Name and CN for Groups.
strQuery = "<GC://" & strDC & "/dc=YOURCOMPANY,dc=com>;(&(objectCategory=person)(objectClass=user)(mail=" & strSMTP & "));adspath;subtree"
'WScript.Echo strQuery
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100000
objCommand.Properties("Timeout") = 60
objCommand.Properties("Cache Results") = True
'Execute query and put into a Record Set
Set objRecordSet = objCommand.Execute
If objRecordSet.bof And objRecordset.eof Then
'SMTP Not Found
objFile.Writeline strSMTP & " " & "User does not exist in AD"
wscript.echo strSMTP & " " & " - User does not exist in AD"
Else
Set objUser = GetObject(objRecordSet.Fields(0).Value)
'call the BESChangePolicy Fn
strPolicyStatus = fnBESChangePolicy(strSMTP)
objFile.Writeline strSMTP & " " & strPolicyStatus
End If
Next
Function fnFindServer(PatternToMatch, StringToSearch)
Dim regEx, CurrentMatch, CurrentMatches
Set regEx = New RegExp
regEx.Pattern = PatternToMatch
regEx.IgnoreCase = True
regEx.Global = True
regEx.MultiLine = True
Set CurrentMatches = regEx.Execute(StringToSearch)
If CurrentMatches.Count >= 1 Then
Set CurrentMatch = CurrentMatches(0)
fnFindServer = CurrentMatch
Else
fnFindServer = ""
End If
Set regEx = Nothing
End Function
Function fnBESChangePolicy(strSMTP)
If fnBESFind(strSMTP) <> "" Then
'build the command to be run, change the capital words to your specific settings
strShellRun = ".\BESUserAdminClient.exe -p BRKPASS -n BESINSTANCETHEBRKISON -change -b " & fnBESFind(strSMTP) & " -u " & strSMTP & " -it_policy " & Chr(34) & "POLICY NAME" & Chr(34)
Set objShell = CreateObject("WScript.Shell")
'the command you wish to run
Set objWshScriptExec = objShell.Exec(strShellRun)
Set objStdOut = objWshScriptExec.StdOut
fnBESChangePolicy = "Policy Changed"
wscript.echo strSMTP & " " & " - Policy Changed"
Else
fnBESChangePolicy = "User does not exist on the BES"
wscript.echo strSMTP & " " & " - User does not exist on the BES"
End If
End Function
Function fnBESFind(strSMTP)
'build the command to be run, change the capital words to your specific settings
strShellRun = ".\BESUserAdminClient.exe -p BRKPASS -n BESINSTANCETHEBRKISON -find -u " & strSMTP
Set objShell = CreateObject("WScript.Shell")
'the command you wish to run
Set objWshScriptExec = objShell.Exec(strShellRun)
Set objStdOut = objWshScriptExec.StdOut
objRegEx = "[A-Z][A-Z][A-Z][A-Z][A-Z]BES[0-9][0-9]"
'google regular expressions to find out more about how to use them but this one will search for 5 letters A-Z, then the letters BES, then a 2 digit number
'so it would find something like ABCDEBES02. modify it to what your service name could be (or if you only have one server just card code the service name)
strSearchString = objStdOut.ReadLine
strSearchString = objStdOut.ReadLine
fnBESFind = fnFindServer(objRegEx, strSearchString)
End Function