Public/Get-LastLogon.ps1
Function Get-LastLogon { <# .Synopsis Display last logon date for AD users .Description List last logon date of all Active Directory users, needs activedirectory module .Example Get-LastLogon List last logon date of all Active Directory users .Inputs None .LINK about_functions_advanced .LINK about_CommonParameters #> [CmdletBinding( SupportsPaging = $true )] [OutputType('None')] Param () Try { Get-ADUser -Filter * -Properties LastLogonDate -ErrorAction Stop } Catch { Write-Warning $_.Exception.Message If ($_.CategoryInfo.Reason -eq "ADServerDownException" -or $_.CategoryInfo.Reason -eq "AuthenticationException") { Write-Error -Message $_.Exception.Message Break } Else { Write-Warning -Message $_.Exception.Message Break } } } Set-Alias -Name Find-LastLogon -Value Get-LastLogon -Description "Get Last Logon" -Option ReadOnly -PassThru -ErrorAction SilentlyContinue |