directoryservice-accountlocked.ps1 - powershell script by ActiveXperts Software
directoryservice-accountlocked.ps1 checks if the specified user account is locked
Use directoryservice-accountlocked.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select directoryservice-accountlocked.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
directoryservice-accountlocked.ps1 script code
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com ################################################################################# # Script # DirectoryService-AccountLockedInGroup.ps1 # Description: # Check if the user account specified by strAccount on domain strDomain is locked # Declare Parameters: # 1) strDomain (string) - Domain that holds the user account # 2) strAccount (string) - User account name # Usage: # .\DirectoryService-AccountLockedInGroup.ps1 '<Domain>' '<Account>' # Sample: # .\DirectoryService-AccountLockedInGroup.ps1 'DOMAIN01' 'Guest' ################################################################################# # -- Declare Parameters param( [string]$strDomain = '', [string]$strAccount = '' ) # -- Use _activexperts.ps1 with common functions . 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1' ################################################################################# # // --- Main script --- ################################################################################# # -- Clear screen and clear error cls $Error.Clear() # -- Validate parameters, return on parameter mismatch if( $strDomain -eq '' -or $strAccount -eq '' ) { $res = 'UNCERTAIN: Invalid number of parameters - Usage: .\DirectoryService-AccountLockedInGroup.ps1 "<Domain>" "<Account>"' echo $res exit } $command = 'WinNT://' + $strDomain + '/' + $strAccount + ',user' $objUser = [ADSI]$command # -- Print script result if( $objUser.IsAccountLocked -eq 0 ) { $res = 'ERROR: Account [' + $strDomain + '\' + $strAccount + '] is NOT locked' echo $res exit } if( $objUser.IsAccountLocked -eq 1 ) { $res = 'SUCCESS: Account [' + $strDomain + '\' + $strAccount + '] is locked' echo $res exit } $res = 'UNCERTAIN: Account [' + $strDomain + '\' + $strAccount + '] could not be found' echo $res exit ################################################################################# # // --- Catch script exceptions --- ################################################################################# trap [Exception] { $res = 'UNCERTAIN: ' + $_.Exception.Message echo $res exit }