Advertisement
FSCorrupted

Repair Computer Secure Channel

Apr 20th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $Computer=Read-Host "Enter Computer Name"
  2. $Username="$Computer\Administrator"
  3. $domain= (Get-ADDomainController).Domain
  4. $AdminUser=$env:USERNAME
  5. $Password=Get-ADComputer -Identity $Computer -Properties * | Select-Object -ExpandProperty ms-Mcs-AdmPwd | ConvertTo-SecureString -AsPlainText -Force
  6. if(!$Password){$Password=Read-Host "No LAPS Password found / Enter Local Admin Password" | ConvertTo-SecureString -AsPlainText -Force}
  7. $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$Password
  8.  
  9. Invoke-Command -ComputerName $Computer -ArgumentList $domain,$AdminUser -ScriptBlock {$TestSecChannel=Test-ComputerSecureChannel;
  10. if ($TestSecChannel -eq $true){Write-Host "The secure channel between the local computer and the domain "$args[0]" is in good condition."-ForegroundColor Green}
  11. else{$repair=Test-ComputerSecureChannel -Repair -Server $args[0] -Credential $args[1];
  12. write-host "Secure Channel in bad condition"-ForegroundColor Red;
  13. if((Test-ComputerSecureChannel) -eq $true){Write-Host "Secure Channel Repaired"-ForegroundColor Yellow}}} -Credential $MySecureCreds
  14. pause
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement