So basically I have an already functioning script on my remote server. I'm trying to run a powershell script on my pc that would automatically go into remote desktop then run my script over there.
The simple script I'm using now isn't working :
mstsc /v:Server
Invoke-Expression c:\Scripts\script.ps1
$userName = 'administrator'
$sessionId = ((quser /server:server | Where-Object { $_ -match $userName }) -split ' +')[2]
logoff $sessionId /server:server
My script is at c:\Scripts as you can see. Thing is this is ignoring the remote desktop and opening my pc's c:\ instead.
How am I supposed to "stay" on the remote desktop to execute my script?
Also, I'm not sure if my logoff code is working. I found it somewhere in a thread, I would also like some clarifications if it is coded right. I know I can use scheduled tasks, but I am working on using this way instead.
Thanks a lot!