# PS session from GUI

**URL:** <https://forums.powershell.org/t/ps-session-from-gui/13110>\
**Category:** PowerShell Help\
**Created:** [September 9, 2019, 10:13am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110 "2019-09-09T10:13:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kardock](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@kardock](https://forums.powershell.org/u/kardock)\
**Post date:** [September 9, 2019, 10:13am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/1 "2019-09-09T10:13:13Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 9, 2019, 10:21am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/2 "2019-09-09T10:21:52Z")

</div>

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}
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![kardock](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@kardock](https://forums.powershell.org/u/kardock)\
**Post date:** [September 9, 2019, 10:31am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/3 "2019-09-09T10:31:05Z")

</div>

[quote quote=175471]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

[/quote]

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

your solution does not show a prompt window.

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 9, 2019, 10:51am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/4 "2019-09-09T10:51:25Z")

</div>

Kardock,

Lets try with Start-Process then. 😃

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

---

<div class="post-metadata">

**Author:** ![kardock](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@kardock](https://forums.powershell.org/u/kardock)\
**Post date:** [September 9, 2019, 11:37am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/5 "2019-09-09T11:37:07Z")

</div>

we’re getting closer!

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

thanks!

---

<div class="post-metadata">

**Author:** ![kardock](https://avatars.discourse-cdn.com/v4/letter/k/779978/32.png) [@kardock](https://forums.powershell.org/u/kardock)\
**Post date:** [September 9, 2019, 11:47am UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/6 "2019-09-09T11:47:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![david-schmidtberger](https://avatars.discourse-cdn.com/v4/letter/d/ba9def/32.png) [@david-schmidtberger](https://forums.powershell.org/u/david-schmidtberger)\
**Post date:** [September 9, 2019, 2:23pm UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/7 "2019-09-09T14:23:20Z")

</div>

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:  
[pre]  
Start-Process -FilePath PowerShell.exe -ArgumentList “-NoExit -NoLogo -Command New-PSSession $PCName.txt; enter-pssession $PCName.txt”  
[/pre]

---

<div class="post-metadata">

**Author:** ![jasonrobertson](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jasonrobertson/32/164_2.png) [@jasonrobertson](https://forums.powershell.org/u/jasonrobertson)\
**Post date:** [September 9, 2019, 5:48pm UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/8 "2019-09-09T17:48:14Z")

</div>

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)"
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/ps-session-from-gui/13110/9 "2024-05-16T20:31:42Z")

</div>


