Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

disabled AD accounts info

Posted on 2016-09-01
3
Medium Priority
?
112 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

886 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