I have this script to kill VNC precesses and restart VNC service:
$ip = Read-Host 'Enter hostname or IP'
& tasklist /s $ip /FI "IMAGENAME eq winvnc*"
$procid_1 = Read-Host 'pid 1'
$procid_2 = Read-Host 'pid 2'
& taskkill /s $ip /pid $procid_1
& taskkill /s $ip /pid $procid_2
Stop-Service -InputObject $(Get-Service -Computer $ip -Name "uvnc_service")
Start-Service -InputObject $(Get-Service -Computer $ip -Name "uvnc_service")
This command
& tasklist /s $ip /FI "IMAGENAME eq winvnc*"
gives me this output:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
winvnc.exe 3576 0 2,968 K
winvnc.exe 4444 0 5,556 K
And I have to enter PIDs (in this case 3576 and 4444) manually to variables $procid_1 and $procid_2
Is there any way how to pass tasklist output directly to variables?
Thanks in advance for any hints! Josef