Le problème avec le script est qu'il redémarre toujours mon propre PC et non l'adresse IP ou la session mentionnée. Ligne par ligne, ça devrait marcher mais je ne vois pas le problème.Problème avec le script PowerShell pour redémarrer la session à distance
Toutes les suggestions sont appréciés:
#Security Policy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
#Adding the range of IP address for Trading network
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -value '10.22.*'
#IP address of the target PC, hostnames doesn't seems to be working
$targetpc = Read-Host "Please enter the IP Address of the target PC"
New-PSSession $targetpc -Credential(Get-Credential)
$sessionid = Read-Host "Please enter the session ID"
Enter-PSSession -Id $sessionid
Write-Host Test
[string]$forcereboot = Read-Host "Would you like to force reboot the PC ? [y][n]"
if ($forcereboot -eq "y") {
#Restart-Computer -Force
Stop-Process -Name "Notepad"
}
else { Exit-PSSession }