public/Get-tADStaleAccounts.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
function Get-tADStaleAccounts{ <# .Synopsis Get stale accounts. .DESCRIPTION Get stale Active Directory accounts. .PARAMETER SearchBase Specifies the OU to search under. .EXAMPLE Get-tADStaleAccounts Get stale accounts in the current domain. .EXAMPLE Get-tADStaleAccounts -SearchBase 'OU=Sales,DC=expamle,DC=com' Get stale accounts in OU Sales. #> [CmdletBinding()] Param( [Parameter(Mandatory=$false)] [String]$SearchBase = (Get-ADDomain).DistinguishedName, [Parameter(Mandatory=$false)] $Days = '30' ) begin { Write-Verbose -Message ('SearchBase: {0}' -f $SearchBase) Write-Verbose -Message ('Days: {0}' -f $Days) } process { $Result = Search-ADAccount -AccountInactive -TimeSpan $Days -SearchBase $SearchBase | Select-Object SID, Name, objectClass } end { Return $Result } } |