Functions/Get-LockedOutStatus.ps1
|
function Get-LockedOutStatus { <# .Notes AUTHOR: Skyler Hart CREATED: 09/21/2017 13:06:06 LASTEDIT: 2022-09-01 23:01:39 KEYWORDS: REQUIRES: -Modules ActiveDirectory .LINK https://wanderingstag.github.io #> [CmdletBinding()] Param ( [Parameter( Mandatory=$false, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true )] [Alias('User','SamAccountname')] [string[]]$Username = "$env:USERNAME" ) Begin { $cktime = Get-Date -Format t if (Get-Module -ListAvailable -Name ActiveDirectory) { #ad module is installed } else { Write-Warning "Active Directory module is not installed and is required to run this command." break } } Process { foreach ($user in $Username) { $usrquery = Get-ADUser $User -properties LockedOut,lockoutTime $locked = $usrquery.LockedOut $locktime = $usrquery.lockoutTime if ($locked -eq $true) { [PSCustomObject]@{ User = $user Status = "Locked" Date = $locktime CheckTime = $cktime } }#if else { [PSCustomObject]@{ User = $user Status = "Not Locked" Date = "--" CheckTime = $cktime } }#else }#foreach } End {} } |