1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| $login = "domain\user" # ou "$env:USERDOMAIN\$env:USERNAME"
$password = "P@s$WorD"
$serveurad = "srv-de-test" #
$pwdscurestring = ConvertTo-SecureString $password -AsPlainText -Force
$Credential = New-Object -typename System.Management.Automation.PSCredential -ArgumentList $login, $pwdscurestring
$pass_pas_bon = 0
try {
$ss = New-PSSession -Credential $Credential -ComputerName $serveurad -ErrorAction SilentlyContinue
Invoke-Command -ScriptBlock {Get-ChildItem "c:\" > $null} -Session $ss
Remove-PSSession $ss
}
catch {
$pass_pas_bon = 1
}
if ($pass_pas_bon) {
write-host "erreur"
}
else {
Write-Host "OK"
} |
Partager