I know there are other ways (may be even easier) to get this done... my questions is why I'm getting an error when using a variable instead of a session ID (i.e. 1, 2, 3)
cls
$pc = Read-Host "Computer Name: "
echo $pc
Get-Service -Name WinRM -ComputerName $pc | Set-Service -Status Running
Invoke-Command -ComputerName $pc -ScriptBlock { quser }
$session = Read-Host "Session ID: "
$session = $session -as [int]
echo $session
Invoke-Command -ComputerName $pc -ScriptBlock { logoff $session }
if I run:
Invoke-Command -ComputerName $pc -ScriptBlock { logoff 1 }
I get no error... any easy way to get it working with my current script?
Thank you in advance!