mardi 17 mai 2016

PowerShell Remote Sessions inquiry

I'm currently trying to replicate a lockout condition in one of the servers, but to no luck I am not able to do so even when the password I supply is already incorrect, I also don't see this via event viewer whether it succeeds or fails. It just throws an error regarding incorrect password in the PowerShell ISE.

I was wondering if this was the right way to lockout my testID or if its expected that even though I explicitly give a wrong password it wouldn't connect thus the failure isn't recognized or recorded?

[datetime]$time = "05/12/2016 5:30:00 AM"
$username = "DS\Gandalf"
$password ="you_shall_not_pass"
$pass = $password|ConvertTo-SecureString -AsPlainText -Force
$Srv = "MOUNTDOOM_DB_server"
do {
        try{

                $cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,$pass)
                $MyRSession = New-PSSession -ComputerName $Srv -Credential $cred -Authentication default 
                try{
                        Invoke-Command -Session $MyRSession -ScriptBlock {get-date};
                }
                catch{
                        echo "Error!";          
                }
                Remove-PSSession $MyRSession;
        }
        Catch{}
}while($(Get-Date) -le $time)
cls
Write-Host "done"

Aucun commentaire:

Enregistrer un commentaire