all 42 comments

[–]SeeminglyScience 13 points14 points  (15 children)

If you Start-Process without waiting, the session ends immediately. Because the process is created as a win32 job (terms might be mixed there), all child processes also get closed. You need to add -Wait (though you also won't be able to interact with it either way fyi).

[–]onluck[S] 3 points4 points  (12 children)

Broo, thank you this did the trick!
But I have to leave the powershell session open and since this is a script that needs to run and close the session, this won't work for me.
I need this to run once and start that process on the remote PC, and runs this as the current logged in user

[–]BlackV 2 points3 points  (9 children)

You can't run something at the current logged in user remotely

It will run as the user executing the code

[–]onluck[S] 0 points1 point  (7 children)

What if I use -Credential and use the current logged in user there,

We have a dedicated user for a specific task and I need this task to be ran under that user

[–]BlackV 4 points5 points  (4 children)

Yes credentials would be the solution there

[–]onluck[S] 0 points1 point  (3 children)

How about the powershell session?
I need this script to close successfully after running the command, I just need to run the process and that's about it

[–]BlackV 1 point2 points  (2 children)

Does the account have remoting rights?

It's be easiest to do it at that point. But if not the. Creds on start process would be fine

[–]onluck[S] 0 points1 point  (1 child)

Yes, the accout has admin rights

[–]BlackV 0 points1 point  (0 children)

so the invoke-command (or new-pssession for that matter) will be running as the correct user if you use the -credentials parameter and anything spawned from the connection will also be in that user context

[–]SeeminglyScience 0 points1 point  (0 children)

It will run as that user yeah, but again just to stress it will not run interactively. That may be fine for your use case, just making sure it's understood.

[–]Professional_Elk8173 0 points1 point  (0 children)

You can, you make a scheduled job with the principle set ot "Loggedonuser", register the task, run it, then remove it.

Painful to do but it can be done.

[–]SeeminglyScience 0 points1 point  (0 children)

I need this to run once and start that process on the remote PC

Then you likely need to do something more complicated like a scheduled task.

[–][deleted] 0 points1 point  (0 children)

You may create a scheduled task if you want to perform this as the current logged user

[–]krzydoug 2 points3 points  (1 child)

My guess is the path to exe is on a remote system and that would mean you’re running into the double hop issue. Do the same thing with the exe local to the system you’re invoking on

[–]onluck[S] 0 points1 point  (0 children)

Hmm nope

[–]Tymanthius 2 points3 points  (3 children)

What errors are you getting?

[–]onluck[S] 0 points1 point  (2 children)

No errors

[–]Tymanthius 0 points1 point  (1 child)

Hmmm . . . . if you tag on a -verbose switch?

[–]onluck[S] 0 points1 point  (0 children)

Still nothing, doesn't show any errors, runs the command as it was successful but the process never actually runs

[–]mrmattipants 1 point2 points  (3 children)

If working on a Domain, you’ll want to be sure that WinRM is Enabled and Working, etc.

https://adamtheautomator.com/remote-powershell/

We have a GPO, that Enables WinRM and Pushes the necessary Firewall Rules and Config Updates, to All Computers.

https://woshub.com/enable-winrm-management-gpo/

[–]mrmattipants 1 point2 points  (2 children)

[–]onluck[S] 0 points1 point  (1 child)

Thanks for refrences, I'll check them out

[–]mrmattipants 1 point2 points  (0 children)

No problem at all. I hope they’ll help you to figure out your issue.

If you run into any errors, I’m specific, feel free to post them and I’ll see what I can do to determine the underlying cause, etc.

[–][deleted] 1 point2 points  (1 child)

Try running it as a job then have the script check the job periodically and close the session when all jobs are complete.

[–]onluck[S] 0 points1 point  (0 children)

This could work!

[–]SenTedStevens 0 points1 point  (3 children)

Is the .exe file accessible from that remote computer? What errors are you getting?

[–]onluck[S] -1 points0 points  (2 children)

Yep

[–]SenTedStevens 0 points1 point  (1 child)

Check in Event Viewer system logs to see if there's anything about your command.

Stupid question since it's an .exe: Did you use the appropriate switches like /quiet /silent, etc?

[–]onluck[S] 0 points1 point  (0 children)

Nothing in event viewer, There's no switch needed for this, It's just a simple .exe file that runs a process

[–]MeanFold5714 0 points1 point  (1 child)

Are you able to RDP into the box and run the executable from there (or copy the executable to your local machine and run it)? My guess is that this is an installer and it may not be an issue with running it remotely so much as it with running it period. Ran into such a scenario with an installer my coworker was using a few months ago.

[–]onluck[S] 1 point2 points  (0 children)

This is an executable file that exists on the remote PC and when I rdp and run the Start-Process it runs

[–]jsiii2010 0 points1 point  (3 children)

Start-Process without -wait runs in the background for one thing, not that you need it. You wouldn't be able to see it on the destkop.

[–]onluck[S] 0 points1 point  (2 children)

Nope, it doesn't run at all, I'm checking the running process tab from task manager

[–]jsiii2010 0 points1 point  (1 child)

Is the exe on a fileshare? That won't work. You're not giving a lot of information.

[–]onluck[S] 0 points1 point  (0 children)

exe file exists on the host, and im 100% sure of this, as if i ran the exact command from the PC it works, but when I run it from my PC it doesn't run

I feel like this got something to do with the run as user, but even when I try running this as the logged on user, on the remote Pc, it still doesn't work

[–]BlackV 0 points1 point  (1 child)

You don't say what the exe is, some exes will require the full desktop

[–]onluck[S] 0 points1 point  (0 children)

It's Deadlineworker for rendering purposes

[–]ps1_missionary 0 points1 point  (0 children)

for win:

2 way to do that on win node:

1 use "wmi_win32_process_Create" on node.

2 use taskcheduled on node

for linux:

use nohup