Public/Get-ExpiringAccount.ps1
Function Get-ExpiringAccount { <# .Synopsis Lists expiring ActiveDirectory accounts .Description Lists ActiveDirectory expiring over a given TimeSpan (in days) .Parameter TimeSpan Number of days in wich the accounts will expire .Example Get-ExpiringAccount -TimeSpan 30 Lists accounts expiring in 30 days .Example Get-ExpiringAccount -TimeSpan 30 | Export-CSV expiringaccounts.csv Exports accounts expiring in 30 days to a csv .Inputs System.Int .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsShouldProcess = $true, SupportsPaging = $true )] [OutputType([System.Object[]])] Param ( [Parameter( Mandatory = $false, ValueFromPipeline = $true, HelpMessage = "Provide number of days in wich the accounts expire" )] [int]$TimeSpan ) Begin { If (-not $PSBoundParameters.ContainsKey('Verbose')) { $VerbosePreference = $PSCmdlet.SessionState.PSVariable.GetValue('VerbosePreference') } If (-not $PSBoundParameters.ContainsKey('ErrorAction')) { $ErrorActionPreference = $PSCmdlet.SessionState.PSVariable.GetValue('ErrorActionPreference') } } Process { If ($PSCmdlet.ShouldProcess("ActiveDirectory", "Collect useraccounts expiring")) { Try { $PSBoundParameters.AccountExpiring = $true $PSBoundParameters.UsersOnly = $true $ExpiringAccounts = Search-ADAccount @PSBoundParameters } Catch { Write-Warning $_.Exception.Message } } } End { Return $ExpiringAccounts } } Set-Alias -Name Find-ExpiringAccount -Value Get-ExpiringAccount -Description "Get Expiring ActiveDirectory Accounts" -Option ReadOnly -PassThru -ErrorAction SilentlyContinue |