Running a simple BAT file via powershell like the Linux screen command

Michael DeLigny 1 Reputation point
2021-05-21T07:36:21.427+00:00

I know Linux better than I know Powershell. All I am looking for is a way to kick off a bat/cmd file on a remote computer from a local PS command line and not be subject to have the interactive window opened to have that remote bat/cmd process to finish. Basically it is using the screen command where I can detach and attach to that job and connect to different ones running on multiple remote machines. I'd like to know the status of that job. Right now I can't even get a single line command to kick off the bat file. This is the command I am currently running.
invoke-command NJEBNXS-5004-12 { start-process "c:!20H2 Retail Stores\Upgrade this pc.bat" }

And then when I log into that computer I don't even see it running using process explorer. So that simple command isn't even kicking off the BAT file. Does me logging into that computer kill that command? I'm just a little lost and have been reading about PS for hours now, getting a little overwhelmed since I don't know the basics yet. Since that job can take a couple of hours on a machine I'd like to be able to ATTACH to that same job to get the status if possible. Even if a user is using the computer. This is a domain environment and I have admin rights on all machines. Can someone possibly walk me thought his like I'm a child? I know I'm doing something wrong and when troubleshooting Linux issues it pretty much always boils down to access/rights. Could this be an issue here also?

Anyway, any help I'd appreciate it. I'd even love to maybe share a screen session with you, or pay you for your time for the help. I know it's probably not that big of a problem for mare advanced users, but I'm under the gun and have to get my feet on the ground floor going 1000 MPH. :)
Thanks!

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,280 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 27,851 Reputation points Microsoft Vendor
    2021-05-21T09:34:15.4+00:00

    Hi,

    The process was killed when the session to the remote computer ended. You can add the "-wait" switch to wait for the process.

    invoke-command NJEBNXS-5004-12 { start-process "c:\20H2 Retail Stores\Upgrade this pc.bat" -wait}  
    

    Or you can keep the session open like below.

    $session=New-PSSession -ComputerName NJEBNXS-5004-12  
    invoke-command -session $session { start-process "c:\20H2 Retail Stores\Upgrade this pc.bat" }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments