PS session from GUI

Welcome Forums General PowerShell Q&A PS session from GUI

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

 
Participant
1 week, 2 days ago.

  • Author
    Posts
  • #175459

    Participant
    Topics: 8
    Replies: 10
    Points: 124
    Rank: Participant

    hi everyone,

    I'm creating a GUI to allow technicians to manage some computers and I ran into something where I have no idea how to do.

    I have a list of tools available to the tech (PSExec, Remote Desktop, Computer Management)

    I wish to add the option to start a PS session but I am unable to have it on screen.

    I create the session from a textbox input with this:

    $session = new-pssession -computerName $PCName.text

    Next step, I want to display the session as a command prompt window. I have no idea how to do that. All I tried has failed.

    can someone help me with this?

    thanks!

  • #175471

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kardock,

    Give this a try and let me know if it resolves the issue. I would add where are using pulling the variable $PCName.text? This would have to be accounted for.

    powershell.exe -command {New-PSSession -ComputerName $PCName.text}

     

  • #175477

    Participant
    Topics: 8
    Replies: 10
    Points: 124
    Rank: Participant

    Kardock,

    Give this a try and let me know if it resolves the issue. I would add where are using pulling the variable $PCName.text? This would have to be accounted for.

    powershell.exe command {New-PSSession ComputerName $PCName.text}
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    as stated, $PCName.text is a textbox in my GUI.

    your solution does not show a prompt window.

  • #175489

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kardock,

    Lets try with Start-Process then. 😀

    Start-Process -FilePath PowerShell.exe -ArgumentList "-NoExit -NoLogo -Command New-PSSession $PCName.txt"
  • #175498

    Participant
    Topics: 8
    Replies: 10
    Points: 124
    Rank: Participant

    we're getting closer!

    with this last command, I can open the command prompt but the location is my pc, not the session!

    thanks!

  • #175501

    Participant
    Topics: 8
    Replies: 10
    Points: 124
    Rank: Participant

    hey is there a way to send a command to an opened promp? if so, I could easily send the enter-pssession cmdlet and deal with the rest

  • #175540

    Participant
    Topics: 23
    Replies: 154
    Points: 367
    Helping Hand
    Rank: Contributor

    just tested on my machine (be careful here as you also need to think about how to clear the stale pssessions)
    but the following worked:

    Start-Process -FilePath PowerShell.exe -ArgumentList "-NoExit -NoLogo -Command New-PSSession $PCName.txt; enter-pssession $PCName.txt"
    
  • #175591

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    Helping Hand
    Rank: Contributor

    Kardock,

    It depends on how you are passing the data. The $PCName isn't going to work well becasue its not part of the powershell environment. You will need to set this and write it out. Also you don't need to use New-PSSEssion if you are going to enter it as well, just go ahead and enter it. What commands are you looking to run once the session is started? You may be better off with Invoke-Command.

    Start-Process -FilePath PowerShell.exe -ArgumentList "-NoExit -NoLogo -Command Enter-pssession $($PCName.txt)"

You must be logged in to reply to this topic.