Automatic Password Expiration Email

This script will go through the OU you specify and email the users that their password will expire.


  1. Dim oConnection ‘As ADODB.Connection
  2. Dim oRecordSet ‘As ADODB.RecordSet
  3. Dim strQuery ‘As String
  4. Dim strDomainNC ‘As String
  5. Dim oRootDSE ‘As IADs
  6. Dim oDirObject ‘As Variant
  7. Dim vArgs, x
  8. Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
  9. Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
  10.  
  11. On Error Resume Next
  12.  
  13. ‘ Find the domain naming context
  14. set oRootDSE = GetObject("LDAP://RootDSE")
  15. strDomainNC = oRootDSE.Get("defaultNamingContext")
  16. set oRootDSE = Nothing
  17.  
  18. ‘ Setup the ADO connection
  19. Set oConnection = CreateObject("ADODB.Connection")
  20. oConnection.Provider = "ADsDSOObject"
  21. oConnection.Open "ADs Provider"
  22. Set vArgs = WScript.Arguments
  23.  
  24. if VArgs.Count <> 2 Then
  25.    wscript.echo "USAGE: cscript expirepassemail.vbs  "
  26.    wscript.echo "USAGE: cscript expirepassemail.vbs 110 120"
  27.    wscript.quit
  28. end if
  29.  
  30. min = vArgs(0)
  31. max = vArgs(1)
  32.  
  33. Set oCommand = CreateObject("ADODB.Command")
  34. Set oCommand.ActiveConnection = oConnection
  35. oCommand.CommandText= "," &amp; strDomainNC &amp; ">;(objectCategory=user);distinguishedName,cn,name;subTree"
  36. oCommand.Properties("searchscope") = 2
  37. oCommand.Properties("Page Size") = 1000
  38. oCommand.Properties("Timeout") = 15
  39. Set oRecordSet = oCommand.Execute
  40.  
  41. if oRecordSet.Eof then
  42.   response.write "No objects were found"
  43.   WScript.Quit(0)
  44. Else
  45.   Dim vClasses ‘As Variant
  46.   Dim strClass ‘As String
  47.   Dim mysid ‘As variant
  48.  
  49.   wscript.echo "List of users and password information"
  50.   wscript.echo "           Max: " &amp; max &amp; ", Min: " &amp; min
  51.   wscript.echo "————————————–"
  52.  
  53. ‘  Iterate through the objects that are in the query results
  54.  
  55.    While Not oRecordset.Eof
  56.       Set usr = GetObject("LDAP://" &amp; oRecordset.Fields("distinguishedName").Value)
  57.       If (instr(usr.SamAccountName, "$") = 0) and instr(usr.adspath, ".Global") = 0 Then
  58.          Err.Number = 0
  59.          dtmValue = Usr.PasswordLastChanged
  60.          If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
  61.             flags = usr.get("userAccountControl")
  62.             If flags And ADS_UF_DONT_EXPIRE_PASSWD Then
  63.                expire = "noexpire"
  64.             Else
  65.                expire = "Expires"
  66.             End if
  67.             If (int(DateDiff("d", dtmValue, Date)) > int(min)) and (int(DateDiff("d", dtmValue, Date)) < int(max)) Then
  68.                wscript.echo usr.cn &amp; " " &amp; expire &amp; " in " &amp; 120DateDiff("d", dtmValue, Date) &amp; " days"
  69.                if 120DateDiff("d", dtmValue, Date) < 0 then
  70.                   wscript.echo "      Expired! " &amp; 120DateDiff("d", dtmValue, Date)
  71.                   Set objMessage = CreateObject("CDO.Message")
  72.                   objMessage.Subject = usr.cn &amp; " Expired"
  73.                   objMessage.Sender = "DoNotReply "
  74.                   objMessage.From = "Do Not Reply"
  75.                   objMessage.To = ""
  76.                   objMessage.TextBody = usr.samaccountname &amp; " has already expired."
  77.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  78.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
  79.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  80.                   objMessage.Configuration.Fields.Update
  81.                   ‘ objMessage.Send
  82.                else
  83.                   response.write 120DateDiff("d", dtmValue, Date)
  84.                   Set objMessage = CreateObject("CDO.Message")
  85.                   objMessage.Subject = "Your network and email password is expiring"
  86.                   objMessage.Sender = "DoNotReply "
  87.                   objMessage.From = "Do Not Reply"
  88.                   objMessage.To = usr.samaccountname &amp; "@"
  89.                   objMessage.TextBody = usr.samaccountname &amp; "@ : Your password will expire in " &amp; 120DateDiff("d", dtmValue, Date) &amp; " days!  Please change it to avoid disruptions."
  90.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  91.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
  92.                   objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  93.                   objMessage.Configuration.Fields.Update
  94.                   objMessage.Send
  95.                end if
  96.             End If
  97.          End If
  98.       End If
  99.     oRecordset.MoveNext
  100.     Wend
  101. End If
  102.  
  103. ‘Clean up
  104. Set oRecordset = Nothing
  105. Set oConnection = Nothing

Removing all the Groups from a User

This script is normally used by passing the argument of the username by executing cscript script.vbs <username> but the username could easily be hardcoded.

Set vArgs = WScript.Arguments

UserName = vArgs(0)

Const ADS_PROPERTY_DELETE = 4
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

strUserPath = "LDAP://" & Username
Set objUser = GetObject(strUserPath)
arrMemberOf = objUser.GetEx("memberOf")

For Each Group in arrMemberOf
Set objGroup = GetObject("LDAP://" & Group)
objGroup.PutEx ADS_PROPERTY_DELETE, "member", Array(UserName)
objGroup.SetInfo
Next

Mapping a Drive with VBScript

So I recently wrote a very long and complex login script to replace the login scripts we currently have here and figured I would share certain parts of it here incase anyone else stumbles upon it and learns something.

Define these variables for both commands

Set objNetwork = CreateObject("Wscript.Network")
Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")


This function was written to map and F drive to a specific server and share.
Sub MapFDrive()

'Checks to see if they have the drive mapped, if so then it deletes it.
If objFileSys.DriveExists("F:") = True Then
objNetwork.RemoveNetworkDrive "F:", True, True
End If

'Maps the Drive.
objNetwork.MapNetworkDrive "F:", "\\Server\Share"
'Gives the drive a name so it's not just <share name> on <server> (Drive:).
objShell.nameSpace("F:\").Self.name = "Sharename can be whatever you want."

End Sub


And this one, which is a little more complex, allows for dynamic mapping via the script
Sub MapDrive(strFileServerPush, strDriveLetter, strMapPath, strDriveName)

'Checks to see if they have the drive mapped, if so then it deletes it.
If objFileSys.DriveExists(strDriveLetter) = True Then
objNetwork.RemoveNetworkDrive strDriveLetter, True, True
End If

'Constructs the path to map the drive.
strPath = "\\" & strFileServerPush & "\" & strMapPath
'Maps the Drive according to the path above.
objNetwork.MapNetworkDrive strDriveLetter, strPath
'Gives the drive a name so it's not just <share name> on <server> (Drive:).
objShell.nameSpace(strDriveLetter & "\").Self.name = strDriveName

End Sub


The above function is called like so:

MapDrive “<Server Name>”, “<Drive Letter>”, “<Share Name>”, “<Whatever you want to name it>”

Mondays

It’s rainy. It’s miserable.. IT’S MONDAY!

It seriously could not be a more stereotypical monday but social science takes no breaks my friends. Today was day 1 of a new traffic experiment and much to my enjoyment, there was a civic on the road whom I could let go and they said thanks. 1 for 1.

However, there were tons of people who were just driving like absolute assholes. I am not sure if it was the rain or because it was monday and people didn’t want to be on the road. There was a lot of cutting people off, no directional use and even the running of a stop sign which almost ended in a collision.

On the family side, Zach has mastered the riding of a two wheeler, which is great, I think for his 5th birthday I’m going to buy him a new bike, he loves his current but he likes the handbrakes on my bike and I think he would love it if he could stop like daddy. Not sure if they have kids bikes with freewheel, but that would be huge.

Well I guess I should start my work day.

Later.

Traffic Experiments

Over the past few weeks I have been doing various experiments with traffic and people.

Experiment 1: Let everyone go and see who does the thank you wave.

Results of experiment 1: People are douchebags, most people didn’t wave thank you which leads into experiment 2.

Experiment 2: Let only people go that aren’t in luxury cars.

Results of experiment 2: Interesting, almost all of them waved thank you and one guy actually gave me the thumbs up out his window after waving thank you.

Conclusion: People in luxury cars are pretty much assholes and think that they don’t have to wave thank you because they are in a car thats more expensive so you should automatically let them go because they are socially superior to you. Bullshit.

Next weeks experiment won’t be so much of an experiment as me being a jerk.

I am only going to let people driving honda civics go.

Happy Turkey Day.

Yeah.

Schoolyard Heroes – Abominations

This is an amazing release from a great unknown band out on the west coast. I was and still am a huge fan of the first two albums so when this was released I ordered it the first day it came out, but am just now getting a chance to write about it. The album hits hard but there are actually a few softer songs, which suprised me but they were still lyrically pretty gruesome.

This is the third major release from Schoolyard Heroes

Total time: 48:05
Year: 2007
1. Dude, Where’s My Skin? 2:37
2. The Plastic Surgery Hall Of Fame 3:17
3. Cemetery Girls 5:09
4. Violence Is All The Rage 3:05
5. Children Of The Night 3:44
6. The Last Man On Earth 3:21
7. Razorblade Kisses 3:31
8. Sometimes They Come Back 4:15
9. Beautiful Woman Hunter 4:24
10. All The Pretty Corpses 5:15
11. Screaming “Theater” In A Crowded Fire 5:59

Garth Marenghi’s Darkplace

A retarded Dark Shadows style comedy horror not worth wasting your time on… or the greatest masterpeice ever to grace the small screen? You decide.

Ok I’ll decide.

It’s perfect, it’s cinematic goliath, terrible acting, awesome dialog, a lot of slow motion (I mean a lot of slow motion), horrible effects, puns.. puns.. puns.. and of course, the director as the starring role.

When it first came on I thought it was a commercial for super deluxe but it kept going and looked cheesy, so of course I was going to watch it and for a random watch, I must say I was impressed. Not with the acting.. or the effects, story line, dialog, scenery, the jokes or in general the characters but more than someone had the balls to make something like this and actually put it on TV on the time when I expected Futurama on.

Would I watch it again? Of course I would.

These are the gems kept from american TV for too long.

I hope they place the rest of the series on Cartoon Network.

It’s time for Family Guy so I’m out.

Well last night sucked.

It however can be fixed easily with a few of these badboys. Today isn’t looking good. It’s pouring rain and crappy out. Looks like today is going to be a nice day to close early.

3am..

Well it’s 3am almost 3:30 and I can’t sleep.

It’s abnormally warm outside though, 54 degrees F (12.2 C for you Will) and very peaceful out. I just stood outside thinking and there was absolutely no noise, it was actually kind of creepy. Today (Yesterday) at the store was dead and tomorrow (Today) isn’t looking much better with an 80% chance of rain. I’d like to start putting some reviews up for various things I’ve watched / played / thrown away / set on fire over the past month or so and I think I will start doing that tomorrow.

For everything I review I’m going to attempt to put a gallery up since I finally got that fixed inside the website. So stay tuned for some reviews and I’m going to try and get some sleep.

Out.