Launch function in new Powershell window

Welcome Forums General PowerShell Q&A Launch function in new Powershell window

This topic contains 4 replies, has 3 voices, and was last updated by

6 months, 2 weeks ago.

  • Author
  • #103547

    Points: -18
    Rank: Member


    Just wondering as to how I can get the following accomplished.

    I have a $profile that consist of functions.
    The functions are that of PSSessions to our messaging environments

    What I would like is to be able to type in the pre-loaded function say for PSSession to Exchange and have it launch in a Powershell window so that I can have separate windows.

    Currently I am having to open individual PS instances and running the function depending on what I want to establish connection to.

    Any help would be appreciated. Thanks in advance


  • #103550

    Points: 1,759
    Helping HandTeam Member
    Rank: Community Hero

    That will be tricky.

    You'll need to have your script run PowerShell.exe to start a new process, and pass a command line switch to have the new process run whatever it is you want running in the new window.

    PowerShell isn't a multi-window application like Word; each window is a fresh standalone process.

    • #103558

      Points: -18
      Rank: Member

      Wow, Wasn't expecting an answer from the Powershell Legend himself.

      I will research further but I'm guessing the command line switch will be some sort of bat file to execute the commands? Possibly not in the form of a function but instead a .ps1 file.

      Thanks Don!

  • #103585

    Points: 77
    Rank: Member

    here is a snippet that i use (i need this script to be called from a parent script to execute a process that needs to run as a seperate user instance)

    #script must contain fqdn path to ps1 file
    $script = ""
    $commandLine = "-noexit & $script"
    $credential = Get-Credential
    Start-Process powershell.exe -Credential $credential -ArgumentList $commandline
    • #103876

      Points: -18
      Rank: Member

      Appreciate the feedback and guidance @david

The topic ‘Launch function in new Powershell window’ is closed to new replies.