Solved

disabled AD accounts info

Posted on 2016-09-01
3
59 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
Comment Utility
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 5

Expert Comment

by:sAMAccountName
Comment Utility
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
Comment Utility
thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now