Solved

disabled AD accounts info

Posted on 2016-09-01
3
95 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

617 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