Help disabling expired user accounts in AD

I'm looking for a bit of help here... I'm trying to create a vb script that looks for all user accounts that has expired before today and disables them. After a
LOT of scrounging the interwebs I've been able to scraped together the bellow VB script that lists all the expired user accounts that are still active, so now i'm trying to have it take the found
accounts and disable them
Option Explicit
Dim dtmAdjusted, lngSeconds, str64Bit
Dim objShell, lngBiasKey, lngBias, k
Dim objRootDSE, strDNSDomain, objConnection, objRecordset, objUser
Dim strBase, strFilter, strAttributes, strQuery, strDN, strAttributes1, strAttributes2, strAttributes3
' Obtain local Time Zone bias from machine registry.
Set objShell = CreateObject("Wscript.Shell")
lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\" _
& "TimeZoneInformation\ActiveTimeBias")
If UCase(TypeName(lngBiasKey)) = "LONG" Then
lngBias = lngBiasKey
ElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then
lngBias = 0
For k = 0 To UBound(lngBiasKey)
lngBias = lngBias + (lngBiasKey(k) * 256^k)
Next
End If
' Convert current date/time value to UTC.
dtmAdjusted = DateAdd("n", lngBias, Now)
' Find number of seconds since 1/1/1601.
lngSeconds = DateDiff("s", #1/1/1601#, dtmAdjusted)
' Convert the number of seconds to a string
' and convert to 100-nanosecond intervals.
str64Bit = CStr(lngSeconds) & "0000000"
' Determine DNS domain name.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory.
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objRecordset = CreateObject("ADODB.Recordset")
objRecordset.ActiveConnection = objConnection
' Search entire domain.
strBase = "<LDAP://dc=globalgiving,dc=local>"
' Filter on expired user accounts.
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(accountExpires<=" & str64Bit & ")(!accountExpires=0)(!userAccountControl:1.2.840.113556.1.4.803:=2))"
' Retrieve Distinguished Names.
strAttributes = "sAMAccountName"
' Use ADO to query AD.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objRecordset.Source = strQuery
objRecordset.Open
' Enumerate expired user accounts.
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("sAMAccountName")
Wscript.Echo strDN
objRecordSet.MoveNext
Loop
' Clean up.
objRecordset.Close
objConnection.Close
Set objRootDSE = Nothing
Set objConnection = Nothing
Set objRecordSet = Nothing
I tried adding: 
strDN.AccountDisabled = True
strDN.SetInfo
but I get :
(66, 1) Microsoft VBScript runtime error: Object required: 'jtest'
jtest is one of the test accounts I have on my AD.
Any suggestions or pointers anyone can give me? I found a 4 line power script that dose exactly what i want, but power script isn't an option for me :(

Start with this:
'change this
' Retrieve aDS path to user object
strAttributes = "aDSPath,sAMAccountName"
' Enumerate expired user accounts.
Do Until objRecordSet.EOF
Set account = GetObject(objRecordSet.Fields("aDSPath"))
Wscript.Echo account.SamAccountName
account.AccountDisabled = True
account.SetInfo
objRecordSet.MoveNext
Loop
¯\_(ツ)_/¯

Similar Messages

  • Disable OID User account after 90 days of inactivity - OIM

    Hello there,
    I have a requirement where I have to disable a users account if he/she has not logged in since last 90 days into our environment(OID). The users are authenticated via OAM when they are logging in. Does anybody has any idea which attribute in which object class in OID needs to be checked for the last login attempt made by the user and what is the datatype of the same? Is it a date that I can compare after making a initial LDAP context to OID and pointing to each single user?
    Really need a solution for this. Please respond.
    Many Thanks,
    - oidm.

    Check the schema description at:
    http://download.oracle.com/docs/cd/B28196_01/idmanage.1014/b25348/schema.htm#CFHCGFCC
    You create a code that runs daily, check for the last login dates and, if is older than 90 days, you disable the OID user.

  • Disable OID user account

    I am new to OID, but very familar with Novell eDirectory and Microsoft Active Directory.
    Both Novell eDirectory and Microsoft Active Directory have the ability to disable login accounts so they can not be used for login (ie say when a user leaves your company).
    I have been unable to find in OID how to disable a user account, could someone point me to that please?
    B

    there is an attribute called "orclisenabled" and you can disable a user by setting this attribute to "Disabled"

  • How to temporarily lock or disable a user account

    Hi, I need help on the easiest way to do the following:
    I want to temporarily disable one of the user accounts on my Mac so it cannot
    be used.
    I do not want to delete the account, just block it
    Thanks

    Aha! Now that's the kind of info I was looking for.
    To hide the user with short user name "jim" from the login window, first log in to an admin account, launch Terminal, and paste in these two lines:
    sudo defaults write /Library/Preferences/com.apple.loginwindow \
    HiddenUsersList -array-add jim
    To unhide the account, enter this:
    sudo defaults delete /Library/Preferences/com.apple.loginwindow \
    HiddenUsersList

  • How to renew an expired user account ?

    Version:11.2.0.1
    OS : RHEL 5.4
    Password for one of our DB user(schema) has expired . The user was using DEFAULT profile
    SQL> select resource_name, RESOURCE_TYPE, limit FROM DBA_PROFILES where profile = 'DEFAULT' AND resource_name like 'PASSWORD%';
    RESOURCE_NAME                    RESOURCE LIMIT
    PASSWORD_LIFE_TIME               PASSWORD 180
    PASSWORD_REUSE_TIME              PASSWORD UNLIMITED
    PASSWORD_REUSE_MAX               PASSWORD UNLIMITED
    PASSWORD_VERIFY_FUNCTION         PASSWORD NULL
    PASSWORD_LOCK_TIME               PASSWORD UNLIMITED
    PASSWORD_GRACE_TIME              PASSWORD 7
    6 rows selected.This schema is used only by apps server ie. No manual logins from SQL*Plus or PL/SQL developer .
    Both apps team and me (the DBA) have forgotton the password.
    SQL> select account_status from dba_users where username = 'PARF_CALIB_USR';
    ACCOUNT_STATUS
    EXPIRED
    SQL> alter user PARF_CALIB_USR account unlock;          --- Unlock won't help
    User altered.
    SQL> select account_status from dba_users where username = 'PARF_CALIB_USR';
    ACCOUNT_STATUS
    EXPIREDI think this can be fixed by setting a new password (ALTER USER parf_calib_usr IDENTIFIED BY newpassword ; )
    But I want to keep the old password and renew this user account. Is this possible ?

    expired means that your password is too old not blocked, you must change it:
    alter user <username> identify by <new_password>;
    in your profile you has set PASSWORD_LIFE_TIME = X days, if your user password has more than X days it will expired. You can set another value or unlimited to password_life_time to make the password forever (not recommended) or more life time.
    Edited by: Fran on 03-dic-2012 2:07

  • How to disable guest user account on iMAC

    I upgraded to Lion and now I have a guest user account on the log in screen. I want to disable this account. How do I get rid of it?

    System Preferences > Users & Groups > Guest User (you may need to authenticate) and uncheck "Allow guests to log in to this computer".

  • How to disable a user account and issue CoA via REST? (ACS 5.4)

    Like the subject line says, I need to disable user accounts via REST, as well as issue CoA doing the same. Is this even possible? I've been trying for a few days now and I can do GET queries on user accounts, but I can't get anything to work using PUT.

    According to this document it should be possible to use the PUT method.
    http://www.cisco.com/en/US/docs/net_mgmt/cisco_secure_access_control_system/5.4/sdk/rest.html
    Could you please tell us how are you using the PUT method? I could try to replicate it in my lab.
    Best regards

  • Help please with User Accounts in Windows on X61 Tablet PC

    I kept getting the "Blue Screen of Death" and so I decided I would reformat the Hard Disk and reinstall everything. During the installation process, the User "Administrator" and my user account are both on the Welcome screen. Under User accounts, under "Administrator User" it says quote "The administrator account is only visible on the Welcome screen when no other user accounts exist (except the quest account), or when you start your computer in Safe Mode". This still is showing regardless that I have my name as a User and as administrator. Any help on getting this to not show would be great. I have a netbook with Windows XP and it just shows my name as a user and under user accounts just my name and guest. Thanks for the help.
    G

    You are right, can only have one open. You have to log out of a user before logging in to another user to use iTunes. Do not use the fast user switching ability of Windows.

  • Need help getting multiple user accounts access an app and its data

    Hello All,
    We recently got a new iMAC. We set up 3 user accounts in it. Two are admin accounts (one for me and one for my husband). The third is a user account with parental controls turned on (for our kid). Here is the basic setup:
    1. Accnt1 - admin
    2. Accnt2 - admin
    3. Accnt3 - user
    Now, I installed the complete national geographic application on the iMAC along with all the data. This is a 6 CD set that took several hours to install. I installed it logged in with Accnt1 (please see above). This installed all the data (150 years worth of data) onto the Documents folder for Accnt1.
    The installation was successful and when I launch the application, I can view all the data from Accnt1.
    So what is the problem? I tried logging in from Accnt2 and Accnt3. While the applciation is visible and will launch from both those user profiles, no data gets displayed. My guess is that this is because the data from the 6 CD's got installed onto the Documents folder for Accnt1 which is not viewable/accessible from Accnt2 and Accnt3. Therefore, nothing gets displayed.
    How do I fix this issue without reinstalling the software so that ALL 3 user accounts on my iMac can access the application AND its data?
    My guess is that I will have to provide user permissions/access to the Documents folder for Accnt1 such that both Accnt2 and Accnt3 are read/write. I tried to do that via the Finder and 'More info' operation wherein I click on the tiny lock icon at the bottom of the screen and add Accnt2 and Accnt3 as read/write. But this does not fix the problem for ALL folders further down and I dont want to fix each and every folder.
    Is there a quick way to resolve this problem? Can I fix this issue via a terminal window with a command?
    Please do help me out.
    Thanks in advance
    Anonymous76

    Move the data folder out of A's documents folder and into /Users/Shared. Then, control-option-command-drag the data folder from its new location back to its original location in A's documents folder. This makes an alias. Log in to the other user accounts and repeat the process for making aliases, to each user's Documents folder.
    You might also contact the developer and politely suggest that they learn how to write programs properly for Mac OS X.

  • Need help with network user accounts on Mac server App on Yosemite, any tips?

    I've been trying to set up a small network with the Server app on Yosemite. I don't want to do anything crazy with the server, I'd just like to know how I can set up network user accounts so that they can login from other Mac computers on the same network. I already have Open directory set up, the Macs that will be used on the network with the server have already been joined to the server under login options. I have created the network user account, I have also joined the user account to a group that I created. When I try to login to the network account from one of the Macs, it doesn't work. I'm pretty rookie with Mac server, can anyway give me any pointers of what I should be doing? Or if I am doing something wrong. Thanks guys.

    The most important step, once you've got Open Directory and DNS set up, with Local Network Users set up in Server.app, is to make sure that all client Macs are using the server's IP address as the primary DNS server in System Preferences > Network, and that they have joined the Network server in System Preferences > Users and Groups > Login Options.
    Having said all that, I have just spent hours setting this all up only to find out that Mail doesn't currently work with Network Homes in 10.10.3 / Server.app 4.1.
    I will be hoping that Apple recognise the bug, and put out a fix soon.

  • Sharing Music Help! 2 Users Accounts, 2 iTunes accounts, share SOME music??

    Hi - I'm new to Mac and iTunes all together (finally joined the cult... and love it!)
    Anyways, My ideal setup is to have 2 User Accounts and 2 Separate iTunes Accounts so my bf and I can buy our own music, obtain separate libraries, yet share SOME music. I want to see all of MY music in the Music Library when I log in, but I still want to be able to transfer some of his music to my phone's playlist and vice versa.
    Currently, our Itunes libraries are stored on each of our user profiles /users/name/music. When I log into iTunes, I see my music and [if his user account is logged on] I can see his under SHARED. But that doesn't allow me to transfer his music to my playlists and in the end, my phone.
    I read Apple's how-to on pointing each of our iTunes to Users/Shared and but then whenever I'm in iTunes it would just be a huge pool of both our music and I have to weed through all of his.
    Any suggestions on how we can both maintain our separate libraries/accounts but share some music (not just listen to each other's music).

    In the Finder. I should have said "In the Finder, create the folder /Users/Shared/Music".
    In case it wasn't clear, all of the instructions should be carried out in the Finder. iTunes should definitely not be running when you move your library and create the aliases.
    A few additional points:
    1. There's nothing significant about the folder location /Users/Shared/Music. You can substitute the name of any folder you want, provided all users will be able to read and write to it.
    2. Beware of having two or more users accessing your shared Music library *at the same time*. (Since you mentioned you want to share your music between two users on a single MacBook, I assumed only one user would access the library at a time.) This only becomes an issue if at some time in the future you share a library in this way between two computers over a networked drive. If two or more users are making simultaneous changes to the same iTunes library, they will stomp all over each other's changes, and very likely corrupt the library. Note that it's also possible to corrupt your music library if you both are simultaneously logged in on your MacBook via "Fast User Switching", and are both simultaneousy running iTunes and making changes to the library. So don't do that. (Not that you ever would.)

  • Disables AD User account in OIM 9.1 still user can access its account

    The following issue is happing on OIM Version: 9.1.0.1866.25
    When disabling a single AD resource, it will appear on IdM in status as Disabled, even though it remains accessible by the user. No change of password occurs.
    Where should I check and how can I fix that.
    Kind Regards,
    Silviu

    What task is attached to Disable of user? Ideally we have an adapter attached to disable user who disables user in target AD system when fired. Login to design console, open you process definition and open disable user task to see what adapter is attached.
    regards,
    GP
    Edited by: Gyanprakash Pandey on Feb 2, 2012 4:33 AM

  • Help, Out of User accounts?!?!

    After purchasing 3 Ipod (40gig, shuffle, nano) products (all under the same account name) and now on my second computer, I have used up all of my 5 user licenses.
    Recently my PC crashed and needed to be re-built. Now when I try to sync my Ipod to the PC Itunes tells me I am not authorized to play the downloaded songs that I have bought.
    Can I do anything? Please help.

    If you've reached the limit of 5 authorisations you have the option once a year to deauthorise them all in one go and start over. By the way, this has nothing to do with the number of products you've purchased and registered. The reason for this is that you have a limit of 5 computers on which you can play purchased content: About iTunes Music Store Authorisation and Deauthorisation
    If your system crashes or your reinstall your operating system without deauthorising iTunes first, even a single computer can use up your limit of 5 authorisations. See also this article: One computer using multiple iTunes Music Store authorizations

  • Help needed - moved user accounts

    I did an upgrade install on my Dual G5 today, but Leopard doesn't know where my users' files are located. I have a very fast (but smaller) HDD for the OS, and moved my user files to a larger HDD. The links were not carried over in the upgrade/install.
    I believe it was a post from Kappy that helped me in moving my user folders initially. Can anyone help me with the needed command line entries needed so that Leopard knows to look to the other HDD for my users?
    Thanks-Gary

    If you've reached the limit of 5 authorisations you have the option once a year to deauthorise them all in one go and start over. By the way, this has nothing to do with the number of products you've purchased and registered. The reason for this is that you have a limit of 5 computers on which you can play purchased content: About iTunes Music Store Authorisation and Deauthorisation
    If your system crashes or your reinstall your operating system without deauthorising iTunes first, even a single computer can use up your limit of 5 authorisations. See also this article: One computer using multiple iTunes Music Store authorizations

  • Disable a User Account WITHOUT Deleting It???

    Is there a way to disable an account without deleting it?

    Yep. When you choose to delete an account you will be prompted whether to delete it immediately or save it to disc image file.

Maybe you are looking for