Scripts/Get-Authorization.ps1
function Get-Authorization { [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Computer, [Parameter(Mandatory=$true)] [string]$Account, [Parameter(Mandatory=$true)] [SecureString]$password_secure, [Parameter(Mandatory=$true)] [PSCredential]$remote_access_creds ) $Proceed_Final = $True $Test_PC_Length = $Computer.length $remote_access_username = $remote_access_creds.UserName #Checks to make sure Machine name does not exceed 15 characters if($Test_PC_Length -ge 16) { $LengthTest = $False $Proceed_Final = $False } Else { $LengthTest = $True } #This is True if Credentials are able to authenticate [pscredential]$credObject = New-Object System.Management.Automation.PSCredential ($Account, $password_secure) try{ $CredentialTest = Test-SWADCredential -Credential $credObject } catch {} if($CredentialTest) { $LogonStatus = $True } Else { $LogonStatus = $False $Proceed_Final = $False } #Verifies if credentials are able to start a PSSession try{ $session = New-PSSession –ComputerName $Computer -credential $remote_access_creds $session_id = $session.Id } catch {} if($null -eq $session) { $Remote_Access = $False $Proceed_Final = $False } else { $Remote_Access = $True } try{Remove-PSSession -Id $Session_id} catch{} #Verifies if machine is online If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) { $TargetStat = $True }else { $TargetStat = $False $Proceed_Final = $False } #Gets Locked out status of the account $LockedStat = Get-ADUser $Account -Properties * | Select-Object -ExpandProperty LockedOut #Gets AD PasswordLastSet $LastPWChangeStat = Get-ADUser $Account -Properties * | Select-Object -ExpandProperty PasswordLastSet ###Return Results $Results = [PSCustomObject]@{ computer = $Computer computer_length_verified = $LengthTest computer_online = $TargetStat room_account = $Account room_account_locked = $LockedStat room_account_credentials = $LogonStatus remote_user = $remote_access_username remote_user_verified = $Remote_Access LastPasswordSet = $LastPWChangeStat Proceed = $Proceed_Final } Return $Results } |