PS session from GUI

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!

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}

 

[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.

Kardock,

Lets try with Start-Process then. :smiley:

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

we’re getting closer!

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

thanks!

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

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]

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