Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remote Powershell connect
#1
Hi,
how can i build an external application to connect to a remote Windows Server via powershell?

with the powershell command:

Enter-PSSession -computername servername -credential domain\user  you can connect to a remote server

In external Application I try :
Dateiname: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
Arbeitsverzeichnis:

Argumente: Enter-PSSession -Computername %computername% -credential domain\user

and no option

When i Connect to a server i can type my Credentials but then the Powershell windows Closed

Thank you for your help
Reply
#2
That's nothing that is related to ASG-RD
Regards/Gruss
Oliver
Reply
#3
Sad 
(11-05-2017, 12:23 PM)DevOma Wrote: That's nothing that is related to ASG-RD

Ok.... but that is not really helpful. Thank you for nothing!


So it is not possible to build an external application to connect remotly to a windows server with powershell?

Sad That is poor!

We use ASG-RD serveral years and now more and more Windowsserver run without a gui so the main admin tool goes to powershell. But a naked Powershell is not so comfortable like ASG-RD.

Have you another idea to connect remotly via powershell ?

How do other users here connect to their Servers without a gui?

With best regards Bjoern Schmidt
Reply
#4
I never tried to connect a RDP session via Powershell and so I don't know :-) But if you google for "Powershell connect RDP session" you find a lot of results that may help you.
Regards/Gruss
Oliver
Reply
#5
(11-05-2017, 01:34 PM)DevOma Wrote: I never tried to connect a RDP session via Powershell and so I don't know :-) But if you google for "Powershell connect RDP session" you find a lot of results that may help you.

Hi,
that is not the point. I dont want to connect via rd protocol. I want to connect with powershell like you connect a ssl connection via putty. And this connection should be clickable over ASG-RD. Please look at my screenshots.

powershell1.png  I start my powershell and connect to a server called bremen with domain\user
powershell2.png now i am connected on a remote powershell on server bremen (i can now act as if i am on the server )
powershell3.png  with exit i can disconnect the powershell session to bremen
externalapp.png this is what i tried to do

when i now start the external application the powershell windows comes up and i can sign in but after the sign in the powershell windod closed immediately


Thank you for your help

if you like we can switch to German


Attached Files Thumbnail(s)
               
Reply
#6
Ok I understand now :-)

Arguments: -noexit "enter-pssession -computername %computername%"

Try that - it's working for me :-) You can also integrate as Tab.
Regards/Gruss
Oliver
Reply
#7
(12-05-2017, 10:45 AM)DevOma Wrote: Ok I understand now :-)

Arguments: -noexit "enter-pssession -computername %computername%"

Try that - it's working for me :-) You can also integrate as Tab.

Perfekt! :D
and the Argument for TAB integration is ?

Thank you
Reply
#8
That's an option in Ext. App. properties
Regards/Gruss
Oliver
Reply
#9
This is a nice addon.. Would be great to have a separate forum for Addon Ideas.
Reply
#10
Sorry , I did not get how to add this as a tab. also is it possible to provide the name of the server as a parameter value ?
Reply
#11
I saw taht teh options all three need to be set . I increzsed the timeout to 3600 seocnds so that i will ahve one hour the tab will be open .

option 1 : wait for exit
option 2 : try to integrate
Option 3 : Stat as a shell process.
Check all these 3 options .
Reply
#12
I'm testing this now with 10.1.5630.1 and it doesn't seem to be doing variable substitution.

I have tried:
-noexit enter-pssession -computername %NAME%
-noexit "enter-pssession -computername %NAME%"
-noexit enter-pssession -computername %COMPUTERNAME%
-noexit "enter-pssession -computername %COMPUTERNAME%"

In all cases, when the shell starts, I get the message:
Enter-PSSession : Missing an argument for parameter 'ComputerName'. Specify a parameter of type 'System.String' and
try again.
At line:1 char:17
+ enter-pssession -computername
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Smile [Enter-PSSession], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.EnterPSSessionCommand

The connection history log shows
Enter-PSSession Start ExtApp C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit "enter-pssession -computername"

The weird thing is that an RDP connection ext app, which I had defined months ago as:
file name: c:\windows\system32\mstsc.exe
arguments: /v:%NAME%

expands the variable just fine.

I tried copying/cloning both of these and have managed to break it now - I'm wondering if perhaps creating a new object results in one that won't resolve variables?
Reply
#13
For testing you should create a simple "notepad" ext. app. - just set "notepad.exe" as filename and arguments "%Computername%" - right click on a connection and choose "Ext. App.=>notepad" - notepad should try to open a text file with the name of your computer - the variable is working in all my environments
Regards/Gruss
Oliver
Reply
#14
Ok, I just tried your test. Created a new app called notepad.

Notepad.exe as file. %Computername% as argument.
On a test connection object, add ext app as a role, configure the ext app to be notepad.
Right click the test object, connect with protocols, ext app. Notepad fires up with no prompt. The log shows destination as notepad.exe

Edit the notepad ext app, substitute test.txt in to the argument field. Test again, and it asks if I want to create a file named test.txt
The log shows destination as notepad.exe test.txt

So it's definitely not pulling the variables - why it's not the same as yours, I don't know!

The other variable handling you added in the program field still works fine.
Reply
#15
If you already configured your connection to use "Ext App" as protocol you do not need to start the connection via "Connect with Protocols" - you can just double click to connect - and then it should work - or you should use "Ext.App" context menu and choose your ext.app. - then it should also work!
Regards/Gruss
Oliver
Reply
#16
I came upon this old thread in search of an answer, but realized none of those provided here were working. The argument needs to involve multiple parameters in order to authenticate you automatically, so you have to write the PS argument as a one-liner.

If you have the credentials saved in ASG for the system you wish to remote into, create an External Application with the following parameters:
  • Name: Powershell Session
  • File name: powershell.exe
  • Arguments: 
    Code:
    -NoExit -NoProfile -Command "$username = '%username%'; $password = ConvertTo-SecureString '%password%' -AsPlainText -Force; $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $password; Enter-PSSession -ComputerName %computername% -Credential $cred -Authentication Default"
**NOTE: you don't need the NoProfile switch. I just use it because I have a large profile that I don't need to waste time loading.**

After saving that, you can right-click your Windows server connection (so long as PSRemoting is enabled properly of course) > select "Ext. Applications" > click "Powershell Session"

Works for me with ASG 2018 on Windows 10.

Hope you find this useful!
Reply




Users browsing this thread: 1 Guest(s)