Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

disabled AD accounts info

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

722 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