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

10 months, 2 weeks ago.

  • Author
  • #103547

    Topics: 5
    Replies: 10
    Points: -19
    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

    Topics: 13
    Replies: 4872
    Points: 1,811
    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

      Topics: 5
      Replies: 10
      Points: -19
      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

    Topics: 23
    Replies: 139
    Points: 260
    Helping Hand
    Rank: Contributor

    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

      Topics: 5
      Replies: 10
      Points: -19
      Rank: Member

      Appreciate the feedback and guidance @david

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

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort