Problem with the script is that always reboots my own PC and not the IP or session mentioned. Line by line it should work but I am not seeing the issue.
Any suggestions are appreciated:
#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 }