Link to home
Start Free TrialLog in
Avatar of JAMES125
JAMES125

asked on

Powershell for inactive active directory accounts

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
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

"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
get-aduser -SearchBase
option might suit you.
ASKER CERTIFIED SOLUTION
Avatar of Neil Russell
Neil Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JAMES125
JAMES125

ASKER

Thanks