POSH-SSH module is not functioning from a button press on a form

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
simon.briggs
Posts: 10
Joined: Mon Jan 04, 2016 1:35 am

POSH-SSH module is not functioning from a button press on a form

Post by simon.briggs » Tue Sep 18, 2018 7:39 am

Win7 64bit
Sapien Powershell Studio 2018, v 5.5.154

I have created a form that should call on the POSH-SSH module to run some UNIX commands. The script runs fine by itself and is picked up by the powershell studio IDE. It auto-completes the commands that are available through having the module loaded.

When pressing the button to run the command nothing happens, nothing in the output console either.

I have tried moving the import of the module to each time the button is pressed in case it wasn't being picked up.

Code: Select all

$form1_Load={
	Import-Module -Name Posh-SSH
}
$pass = ConvertTo-SecureString "PASSWORD HERE" -AsPlainText -force
$pscred = new-object system.management.automation.pscredential ("USERNAME", $pass)
$s = New-SSHSession -ComputerName SERVER -Credential $pscred -acceptkey


$buttonAddUser_Click = {
	$username = $auser.Text
	$unixname = $uuser.Text
	$uuid = $uid.Text
	$ugid = $gid.Text
	if ($ugid -eq "GNAME")
		{ $ugidn = "NUMBER" }
	elseif ($ugid -eq "GNAME2")
		{ $ugidn = "NUMBER" }
	else
		{$ugidn = "NUMBER"}
	$wszone = $zone.Text
	$fullname = $fname.Text
	Write-Host $username $unixname $uuid $ugidn $wszone $fullname
	$adduserscript = { sudo /usr/sbin/useradd -c '"virtual workstation user"' -s /bin/false -d /dev/null -u $uuid -g $ugidn $unixname }
	$enableuserscript = { sudo /usr/sbin/smbadm enable-user $unixname }
	$setpasswordscript = { sudo /root/chpwd.exp $unixname PASSWORDHERE }
	$pass = ConvertTo-SecureString "PASSWORD HERE" -AsPlainText -force
	$pscred = new-object system.management.automation.pscredential ("USERNAME", $pass)
	$s = New-SSHSession -ComputerName SERVER -Credential $pscred -acceptkey
	
	Invoke-SSHCommand -Command $adduserscript -SSHSession $s
	Invoke-SSHCommand -Command $enableuserscript -SSHSession $s
	Invoke-SSHCommand -Command $setpasswordscript -SSHSession $s
}

User avatar
jvierra
Posts: 13143
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: POSH-SSH module is not functioning from a button press on a form

Post by jvierra » Tue Sep 18, 2018 10:50 am

Please run the form in the debugger and step though the button code.

User avatar
simon.briggs
Posts: 10
Joined: Mon Jan 04, 2016 1:35 am

Re: POSH-SSH module is not functioning from a button press on a form

Post by simon.briggs » Thu Sep 20, 2018 5:50 am

Apologies for the lack of response, I've been out of office. I'll try it on Monday morning and post results.

User avatar
simon.briggs
Posts: 10
Joined: Mon Jan 04, 2016 1:35 am

Re: POSH-SSH module is not functioning from a button press on a form

Post by simon.briggs » Mon Sep 24, 2018 1:25 am

Tried running through debug, nothing is coming up in the debug console. Apologies if I am missing something.

User avatar
jvierra
Posts: 13143
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: POSH-SSH module is not functioning from a button press on a form

Post by jvierra » Mon Sep 24, 2018 2:51 am

What did you expect? Did you get to a breakpoint? Do you understand how to use the debugger in PSS?

User avatar
simon.briggs
Posts: 10
Joined: Mon Jan 04, 2016 1:35 am

Re: POSH-SSH module is not functioning from a button press on a form

Post by simon.briggs » Mon Sep 24, 2018 4:57 am

output from the command should be in the form of
Host: server
Output: {results}
Exitstatus: exitcode

I am not familiar with the debugging process I'm afraid. I was expecting it to output everything in the debug window. I set the breakpoint on the line of the command then stepped through the function which didn't bring up any errors.

User avatar
simon.briggs
Posts: 10
Joined: Mon Jan 04, 2016 1:35 am

Re: POSH-SSH module is not functioning from a button press on a form

Post by simon.briggs » Mon Sep 24, 2018 5:01 am

Just found the issue, the variables which build the ssh commands aren't populating the scriptblock. The SSH sessions are returning information but it wasn't being displayed.

Locked