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.
This topic is 5 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
simon.briggs
Posts: 10
Last visit: Mon Feb 01, 2021 6:18 am

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

Post by simon.briggs »

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
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Please run the form in the debugger and step though the button code.
User avatar
simon.briggs
Posts: 10
Last visit: Mon Feb 01, 2021 6:18 am

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

Post by simon.briggs »

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
Last visit: Mon Feb 01, 2021 6:18 am

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

Post by simon.briggs »

Tried running through debug, nothing is coming up in the debug console. Apologies if I am missing something.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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
Last visit: Mon Feb 01, 2021 6:18 am

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

Post by simon.briggs »

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
Last visit: Mon Feb 01, 2021 6:18 am

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

Post by simon.briggs »

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.
This topic is 5 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked