Disable User script

all, I have the following disable user script:
Add-PSSnapIn Quest.ActiveRoles.ADManagement
# Get the Current Date 
$COMPAREDATE=GET-DATE 
# Number of Days to check back.    
$NumberDays=60
$OU=contoso.local/'
GET-QADUSER -SizeLimit 0 -SearchRoot $OU | 
#where { $_.LastLogonTimeStamp.AddDays($NumberDays) -gt $CURRENTDATE } |
where { $_.lastlogontimestamp -le (get-date).adddays(-$NumberDays) } | 
Where {$_.ParentContainer -notmatch "$OU/contoso\Service Accounts"} |
DISABLE-QADUSER
I run the following command as a domain admin on a workstation:
c:\Windows\System32\WindowsPowerShell\v1.0>powershell.exe -command "&'c:\scripts\disable.ps1'"
I get a listing of accounts and then:
Disable-QADUser : Access is denied.
At C:\scripts\disable.ps1:21 char:16
+ DISABLE-QADUSER <<<<
    + CategoryInfo          : NotSpecified: (:) [Disable-QADUser], Unauthorize
   dAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Quest.ActiveR
   oles.ArsPowerShellSnapIn.Powershell.Cmdlets.DisableUserCmdlet
any ideas why I get this and how to fix it?
thanks

Step by step:
This gets all user accounts:
$users=get-qaduser
This filters an out an single OU.
$users=get-qaduser | where{$_.ParentContainerDN -ne 'ou=Service Accounts,dc=contoso,dc-com'}
Now add the exclusion for the logindate
$users=get-qaduser
|
        Where-Object{$_.ParentContainerDN
-ne 'ou=Service Accounts,dc=contoso,dc-com'}
|
        Where-Object{$_.LastLogon
-lt $oldestdate}
Now check $users to be sure it contains what you want.
Now test to see if you can disable them:
$users | Disable-QADUser -WhaztIf
Try it.
¯\_(ツ)_/¯

Similar Messages

  • Remove GrantSendOnBehalfTo disabled user accounts - A novice at scripting

    Hello.  Can anyone help please
    In our exchange 2010 environment we have users who are granted send on behalf to access.  Obviously some users leave and I m finding that there are ghosts left behind which are causing issues with our team who add users into the grantsendonbehalfto
    option using the EMC.  Using the log view we coy out the command and then remove the disabled user from the command and then paste this into an Exchange Powershell command line.  This wrks because it is doing what Exchange EMC does which is rewrites
    the -GrantSendOnBehalfTo option in it new entirety.  
    The problem occurs because I need to remove these en-mass from approx 700 plus accounts.  
    I have tried to modify one user in order to get the script to work but it doesn't.
    This is the error message that happens when I run the script below against a known account with at least 2 disabled users in:-
    Couldn't find object "xxxxxxxx.xx.xxxxxxx.xxx.xx/DisabledUsers/2013-08/Gaynor Collins-Punter". Please make sure that i
     was spelled correctly or specify a different object. Reason: The recipient xxxxxxxx.xx.xxxxxxx.xxx.xx/DisabledUsers/2
    13-08/Gaynor Collins-Punter isn't the expected type.
        + CategoryInfo          : NotSpecified: (:) [], ManagementObjectNotFoundException
        + FullyQualifiedErrorId : F6498844
        + PSComputerName        : ex02-0029.xx.xxxxxxx.xxx.xx
    Am running the script from my local PC
    This is the script I have used.
    # Gather info use get-mailbox -resultsize unlimited$mailboxes = Get-Mailbox zplew1
    Foreach($mailbox in $mailboxes)
    for($i = ($mailbox.GrantSendOnBehalfTo.count)-1; $i -ge 0; $i--)
    $address=$mailbox.GrantSendOnBehalfTo[$i]
    $addressString=$address.addressString
    If($addressString -like "*disabled*")
    $mailbox.GrantSendOnBehalfTo.removeat($i)
    $info >> "C:\Scripts\grantsendonbehalfto.csv"
    $mailbox |set-mailbox -GrantSendOnBehalfTo $mailbox.grantsendonbehalfto
    }If you requiere any more info please let me know.

    #1 - I recommend posting in xchange forum fo rhow to do this
    #2 - Wen an account is disabled most on the information in the object is hidden.  YOu would need to undelete to use the object.
    #3 - Get list as text and validaye al values are not deleted accounts.  Remove deleted and save back.
    ¯\_(ツ)_/¯

  • Need Script to disconnect Mailbox of disabled users

    Hi,
    i have found this Script on Website
    but i'm not able to modify it for our Exchange Server 2010.
    I get Error
    The Windows PowerShell snap-in 'Microsoft.Exchange.Management.Powershell.Admin' is not installed on this machine
    an the mail contains a TXT File with this Text:
    There are  disabled accounts that have active mailboxes
    , has been Disabled
    Run Time: 00:00:24.38
    It dont find list the disabled Accounts with Mailbox. But we have enought Mailboxed from disabled Users.
    Hope someone can help
    Here my script
    $stopwatch = New-Object system.Diagnostics.Stopwatch
    $stopwatch.Start();
    $date = Get-Date -format MMddyy
    $LogFile = "C:\Scripts\Ex\logs\LogFile_$date.txt"
    $grouppath = "OU=de-DE,OU=Useraccounts,DC=intranet,DC=contoso,DC=com"
    write-host "Please wait while I import the Exchange ManagementTools..."
    if (-not (Get-PSSnapin Microsoft.Exchange.Management.Powershell.Admin -WarningAction SilentlyContinue -ErrorAction SilentlyContinue))
          Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
    Import-Module ActiveDirectory
    start-sleep -s 15
    $DisabledAccounts = get-mailbox -resultsize Unlimited –ErrorAction SilentlyContinue –WarningAction SilentlyContinue | where {($_.UserAccountControl -eq "AccountDisabled, NormalAccount") –and ($_.RecipientTypeDetails –ne “RoomMailbox”)}
    $Count = $DisabledAccounts.Count
    Add-Content $LogFile "There are $Count disabled accounts that have active mailboxes"
    Foreach ($Account in $DisabledAccounts)
           else 
                $EmailAddress = $Account.PrimarySMTPAddress.tostring()
                $Name=$Account.SamAccountName
                #Disable-Mailbox $Account.SamAccountName -Confirm:$false
                Add-Content $LogFile "$Name,$EmailAddress, has been Disabled"
    $stopwatch.Stop(); 
    $ts = $StopWatch.Elapsed
    $elapsedtime = [system.String]::Format("{0:00}:{1:00}:{2:00}.{3:00}", $ts.Hours, $ts.Minutes, $ts.Seconds, $ts.Milliseconds / 10);
    Add-Content $LogFile "Run Time: $elapsedtime"
    #Email the logfile to the messaging Group as an attachment
    #Replace the $To with whoever you want to receive the email (group, etc)
    $smtp = "ex01.intranet.contosp.com"
    $To = "Messaging Team <[email protected]>"
    $From = $To
    $Subject = "Termed users for $Date"
    $att = $Logfile
    $body = "Here is today's logfile"
    send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -Attachments $att -BodyAsHtml -Priority high

    Hi,
    Glad to hear the good news, thanks for updating!
    Best regards,
    Belinda Ma
    TechNet Community Support

  • PS script to disable users / Audit and remove Groups / Hide from GAL have bits but need to put it together

    Hi All
    I am trying to get a script together to run against a specific OU (our disabled Users OU) to make the process of leavers more automated.
    I am trying to achieve the 4 main outcomes below
    1. Disable User account 
    2. Hide from GAL
    3. Export users group membership to a file based on SamAccountName
    4. Remove users from all groups except domain users
    I have some parts of this working from other peoples scripts i have found on the web but need to tie it all together which is proving to be beyond my basic scripting ability
    Below is what i have so far, this does disable users / hide from GAL and remove groups however as stated i would really like it to export the group membership to a file before removing them so i have a record should a mistake be made.
    $users= get-aduser -Filter {(Enabled -eq "True")} -SearchBase "ou=Disabled Accounts,dc=test2k8,dc=local"
    Function RemoveMemberships
    param([string]$SAMAccountName)
    $user = Get-ADUser $SAMAccountName -properties memberof
    $userGroups = $user.memberof
    $userGroups | %{get-adgroup $_ | Remove-ADGroupMember -confirm:$false -member $SAMAccountName}
    $userGroups = $null
    $users | %{RemoveMemberships $_.SAMAccountName}
    ForEach ($user in $users)
    set-aduser -identity $user.sAMAccountName -Enabled $false -replace @{msExchHideFromAddressLists=$true}
    exit
    If there is anyone here that can help i would be very grateful
    Many Thanks
    Nick

    Try this:
    $Users = get-aduser -Filter {(Enabled -eq "True")} -SearchBase "ou=DisabledAccounts,dc=test2k8,dc=local"
    Function Remove-GroupMembership
    [CmdletBinding()]
    param
    [parameter(ValueFromPipeline=$true)]
    $Identity
    process
    if ($Identity -is [string] -or !$Identity.memberof)
    $Identity = Get-ADUser $Identity -properties memberof
    Write-Verbose -message $Identity.samAccountname
    foreach ($Group in $Identity.memberof)
    Write-Verbose $Group
    Remove-ADGroupMember $Group -confirm:$false -member $Identity
    $Users | Remove-GroupMembership -verbose 4> c:\users\mmcnabb\desktop\groups.txt
    forEach ($User in $Users)
    set-aduser -identity $user.sAMAccountName -Enabled $false -replace @{msExchHideFromAddressLists=$true}
    It uses the verbose stream to redirect the groups out to a text file of your choice. Please note this is untested so please use with caution.

  • Script to get the List of Disabled Users in UserProfiles

    Hi All,
    can somebody help me in writing a script to get all the disabled users in Share Point userProfiles.
    Thanks
    Kishore

    Hi All,
    can somebody help me in writing a script to get all the disabled users in Share Point userProfiles.
    Thanks
    Kishore

  • Getting error "1013009 Administrator Has Temporarily Disabled User Commands

    Hi All,
    I am getting the error"1013009 Administrator Has Temporarily Disabled User Commands" while executing a report script in Essbase 11.1.1.3
    Appreciate any help..
    Thanks
    Mahesh

    Mahesh wrote:
    Hi All,
    I am getting the error"1013009 Administrator Has Temporarily Disabled User Commands" while executing a report script in Essbase 11.1.1.3
    Appreciate any help..
    Thanks
    Mahesh
    Possible Cause
    When a database is being restructured or any application/database on the server is being copied, you can get this message.
    or
    When a cube is being restructured, commands are restricted because the integrity of the cube has to be stable and no one is allowed to access it.
    or
    Copying an application requires that the Essbase security file be in read/write mode and therefore other applications are not accessible until the process is completed.
    Possible Solution
    In Application Settings, verify that the Allow Commands or Allow Updates options are not selected.
    If not selected select those..and try
    Regards,
    Prabhas
    Edited by: P on Apr 7, 2011 3:36 PM
    Edited by: P on Apr 7, 2011 3:38 PM

  • Getting error "Administrator has temporarily disabled user commands"

    Hi ,
    I am getting the error "Administrator has temporarily disabled user commands" while executing the report script. I have tried creating a new script and getting the same error. We are on 11.1.1.3
    Appreciate any help..
    Regards,
    Mahesh

    It is worth having a read of the following article on "My Oracle Support" - Error "1013009 - Administrator Has Temporarily Disabled User Commands" [ID 1216053.1]
    It gives some examples of what can cause the issue and some bugs, ignore the 9.3.1 patch part.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Disable Inbox Rules for Disable Users

    I have found that when our helpdesk disables an AD user account (terminated employee) that has an Outlook inbox rule to forward the email to an email address outside the organization, emails sent to the former employee are still forwarded to that outside
    email address.  I would like to run a script each day that queries AD for all disabled accounts, removes any forwarding SMTP adresses, then removes all mailbox inbox rules.  I have been trying to use get-aduser against a DC and export the list of
    disabled users, this works fine.  I then take that csv, import it and use -foreach-object to set the forwarding smtp address to null.  I would then like to use the same csv file to run the -removeinbox rule command against the list.  I am having
    a hard time time combining the commands I need into a PS script that works against both AD and Exchange.
    Anyone have some powershell kung fu to assist me?  Thank you!
    ~Eric

    Hi Eric,
    According to your description, I understand that you want a script to get a list of disabled AD user, then removes any forwarding SMTP addresses, then removes all mailbox inbox rules.
    We can run following command to get a list of disabled AD user in PowerShell:
    Get-ADUser -Filter 'Enabled -eq "false"' | select name,userprincipalname
    More details about “How Can I Get a List of All the Disabled User Accounts in Active Directory? “, for your reference:
    http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/12/how-can-i-get-a-list-of-all-the-disabled-user-accounts-in-active-directory.aspx
    Also, run below command to disable forwarding SMTP address and inbox rule:
    Get-Mailbox  -Identity xxxx | Set-Mailbox -DeliverToMailboxAndForward $false
    Get-InboxRule –Mailbox xxxx | remove-InboxRule
    However, we recommend use this disable AD user to disable mailbox.
    By the way, this question will related to the script of Exchange server, please contact relevant team so that you can get more professional suggestions. For your convenience:
    http://technet.microsoft.com/en-us/scriptcenter/dd742246.aspx
    Best Regards,
    Allen Wang

  • How to delete disabled users in SCCM 2012

    Currently we disable user accounts in AD and then move them to a different OU which they stay for 6 - 12 months.
    How can I identify those disabled users accounts and delete them form the SCCM console?
    Thank you

    Thanks for the response but there wasn't a process in place so was tasked with a one time cleanup and we don't have Orchestrator in place.
    I ended up doing the following:
    1.Use a powershell script to output all disabled user ID's
    Get-ADUser
    -Filter 'Enabled -eq $false'
    |Select-Object
    samaccountname
    2. Setup a Query on a collection to gather all these users ID's
    select *  from  SMS_R_User where SMS_R_User.UserName in ("User1", "user2")
    3. Delete the users in the collection

  • Disable user account on Active Directory??

    I sync user account from iPlanet DS to Active Directory through Meta Directory. If I disable user account on iPlanet DS, can meta directory disable the user account on Active Directory Server?

    AD has an attribute called userAccountControl. This attribute has a value of 512 when an AD account is active and 546 when it has been disabled. I flow a constructed attribute called userAccountControl with two rules, one for enable and one for disable. The selection criteria for the enable/disable rule is based upon a change in employee status. For example, (%mv.employeestatus%==T). Another way to do this would be a single attribute constructrion rule that calls an external script (written in Perl) that accounts for multiple conditions and then enables/disables the AD account accordingly. In the attribute flow rule, you flow the constructed attribute userAccountControl to mdsAdUserAccountControl (assuming an AD-Specific schema setting in the AD connector).

  • Outlook Contact Card - Organization Tab disabled users

    In Outlook there is a Contact Card showing detailed information about that person. the Organization tab shows the contact's "Manager", "Shares Same Manager" (other contacts with the same manager), and "Direct Reports" (people
    that report to that contact).
    The problem i am seeing is that Users disabled in Active Directory (people that have left the company) are showing up in the Organization Tab.
    How can i filter out disabled users from this list for anyone using Outlook?
    I cannot permanently delete users from Active Directory until after a disabled account reaches a certain age. Also i would prefer not modifying the disabled Active Directory user accounts.
    We mostly run Outlook 2010 with a few people running Outlook 2013

    Hi,
    Outlook has no control over this, it just displays what it got from the server end. And to my knowledge, there is no such a feature to filter out those users from that list, at least on Outlook client.
    Regards,
    Ethan Hua
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • How to do Archiving of deleted & disabled users in OIM11g

    Hi All,
    As per the requirement we have to do archive of deleted & disabled users in OIM11g(11.1.1.2) after 75days. Can i know how can i achieve this?
    Regards,
    user7609

    Just to recap:
    Your client requirement is to archive users out of OIM after 75 days. This means in addition to actually disabling and/or deleting them, fully removing any traces of them from the system.
    As Kevin & GP said, OIM is just not built to do this. API alone is not going to accomplish this task... you'll also need to include SQL to actually drop data out of tables.
    All that being said, your post said the reason for this was because of a "license for limited users". Oracle Identity Manager is licensed on an active user basis. You really should talk with your Oracle rep to confirm, but I've never had licensing contracts include deleted/disabled users.

  • Disabling User in Solaris

    Is there anyway to change the way the resource adapter for Solaris and Linux disables users so that it uses the native lock provided through passwd rather than setting a random password?
    Scott

    Is there anyway to change the way the resource
    adapter for Solaris and Linux disables users so that
    it uses the native lock provided through passwd
    rather than setting a random password?No there is no way to do that.
    The usage of passwd -d and or -l is limited to certain installations. If you read the man page for passwd you will see that it only works for files as the repository not for any of the other possibilities (NIS or NIS+ or ldap). It also depends on PAM modules to implement this and they do not have to be configured on the system.
    WilfredS

  • How can I change the order of user scripts in Firefox 4?

    ''locking as a duplicate - https://support.mozilla.com/en-US/questions/793457''
    Some of my user scripts only work when arranged in a certain order. I need to figure out how to re-order them in the add-ons manager page.

    Right click the script and choose Execute First/Sooner/Later/Last to move it up or down.
    Hopefully you arn't like me and have a lot of scripts. The page reloads every time you do this and puts you back at the top of the list. It takes forever to adjust any number of scripts. I hope they give us back the ability to drag them into place like in FF3.x.

  • Disabled User Password should not be changed

    Hi,
    We have a requirement that only if the user's status is active, then only administartor must be able to change the user password. Admin should not be able to change the password if the user is in disabled state/locked state.How can we achieve this?please sugest...
    Regards
    Vinoth

    Hi,
    We have made an entity adapter which is taking usr login value from User[in Data object manager] and calling our java method which is making connection to OIM database and getting us the status of user.
    Now if the status of user is disabled method is returning true and on true we have associated our error code to it.
    We are executing our entity adapter in pre-update execution.
    Now when we are changing password of any disabled user we are able to see our error code. But what ever update [either first name update, enable] we are running on that user same error code is appearing.
    Plesae suggest/reply.
    thanks

Maybe you are looking for

  • Access to portal desktop denied through gateway

    I'm trying to get the gateway component to configured and working. I've installed gateway on a separate box from my portal server. When I go to the gateway url (using either https or http) I get prompted to login. Once I submit my user credentials, I

  • Nested list in Pages for iPad

    All I want to be able to do is cascade lists ie 1. text      a. text      b. text           i. text           ii. text      c. text 2. text etc can I do this is iPages on iPad2. All updates installed. This is driving me crazy. Pages is great but for

  • How can I casting from parent class to children class

    Dear, Could someone help me to casting from parent class to children class. I have class like this class parent{ String name; String id; public String getId() { return id; public void setId(String id) { this.id = id; public String getName() { return

  • ISE Internal error suddenly appear

    I started to see this error message suddenly  [500] Internal Error Please contact system administrator. If you are the System Administrator please consult the logs. ISE deployment consists of two nodes one carrying Administration persona (primary) ,

  • Error Message when Sync'ing

    I have been using my Blackberry Pearl 8110 since April and today when I went into the Desktop Manager to sync it with my outlook it started the normal process, went into the Sync Progress screen saying 'processing device calendar' and then came up wi