Solved

disabled AD accounts info

Posted on 2016-09-01
3
81 Views
Last Modified: 2016-09-06
Dear Experts.

Could you please help me with the  powershel code I am trying to amend to get it working  with a specific OU in AD where disabled users are stored?  I noticed some accounts are still enabled and most of them disabled as they should be. I am trying to find out how long account has been disabled or last logged on to system?  here is the code

import-module activedirectory
Search-ADAccount -AccountInactive -TimeSpan 120.00:00:00 -UsersOnly | where {$_.Enabled -eq $false -and $_.Samaccountname -notlike "SystemMailbox*" -and $_.Samaccountname -notlike "SVC_*" -and $_.Samaccountname -notlike "SQL" -and $_.Samaccountname -notlike "test"} | Get-ADuser -searchbase "ou=myou ,ou=users,ou=my ou,DC=mydc,DC=my,dc=local" -Filter {(Enabled -eq $false)} | Select samaccountname | Export-csv h:\test\export\test2.csv -nti

error is

Get-ADUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parame
ters that take pipeline input.
0
Comment
Question by:kuzum
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41780025
Search-ADAccount has the -searchbase parameter.
Example..
Search-ADAccount -searchbase "ou=myou,ou=users,ou=myou,DC=mydc,DC=my,dc=local" -AccountInactive -TimeSpan 120.00:00:00 -UsersOnly | where {$_.Enabled -eq $false -and $_.Samaccountname -notlike "SystemMailbox*" -and $_.Samaccountname -notlike "SVC_*" -and $_.Samaccountname -notlike "SQL" -and $_.Samaccountname -notlike "test"} | Select samaccountname

Open in new window


There is  no such attribute which can tell you when the account is disabled, you can check the Modified attribute to find last date of modification of user object.

There is a LastLogonTimeStamp Attribute, you can refer following article to get more information.
https://blogs.technet.microsoft.com/askds/2009/04/15/the-lastlogontimestamp-attribute-what-it-was-designed-for-and-how-it-works/
0
 
LVL 6

Expert Comment

by:sAMAccountName
ID: 41780047
From a powershell perspective, when you run into this type of error, its often helpful to take each statement and pipe it through "Get-Member" to see what type of object is being sent through the pipeline.  Some cmdlets dont support what comes through the pipeline and some only support the piped object using '-passthrough'
0
 

Author Closing Comment

by:kuzum
ID: 41785823
thank you.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Forest and doamin tree 3 26
IF statment In Powershell 12 17
IDE for Python 5 25
ADModify LDAP Query Help 7 12
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question