We help IT Professionals succeed at work.

Powershell for inactive active directory accounts

JAMES125
JAMES125 asked
on
583 Views
Last Modified: 2012-05-29
I can use the following script to list inactive accouts but how do I narrow the search down to a specific container?

Search-ADAccount -AccountInactive -TimeSpan 30.00:00:00 | Where{$_.enabled -eq $true} | %{Get-ADUser $_.ObjectGuid} | select name, givenname, surname | export-csv c:\users\username\desktop\unusedaccounts.csv -NoTypeInformation

-James
Comment
Watch Question

Neil RussellTechnical Development Lead

Commented:
"SearchBase


Specifies an Active Directory path to search under.

When you run a cmdlet from an Active Directory provider drive, the default value of this parameter is the current path of the drive.

When you run a cmdlet outside of an Active Directory provider drive against an AD DS target, the default value of this parameter is the default naming context of the target domain.

When you run a cmdlet outside of an Active Directory provider drive against an AD LDS target, the default value is the default naming context of the target LDS instance if one has been specified by setting the msDS-defaultNamingContext property of the Active Directory directory service agent (DSA) object (nTDSDSA) for the AD LDS instance. If no default naming context has been specified for the target AD LDS instance, then this parameter has no default value.

The following example shows how to set this parameter to search under an OU.
-SearchBase "ou=mfg,dc=noam,dc=corp,dc=contoso,dc=com"


"

From:: http://technet.microsoft.com/en-us/library/ee617247.aspx

Commented:
get-aduser -SearchBase
option might suit you.
Technical Development Lead
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.