Start powershell with commands

Filip 831 Reputation points
2021-04-01T12:50:15.927+00:00

Hello Everybody.

I want start in powerhsell new powershell window but i want also that window will execute some command rigth when they show up.
I tried somethnig as : "start powershell "dir"
but when i execute it the window still quit.
Can somebody help me?
Thanks for answare.

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,364 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,651 Reputation points Microsoft Vendor
    2021-04-02T03:38:02.593+00:00

    Hi,

    You can add the "-NoExit" switch to "-ArgumentList".

    Start-Process powershell -ArgumentList "-NoExit","-Command dir"  
    

    Best Regards,powerse
    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

0 additional answers

Sort by: Most helpful