Page 1 of 1

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

Posted: Tue Sep 18, 2018 7:39 am
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
}

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

Posted: Tue Sep 18, 2018 10:50 am
by jvierra
Please run the form in the debugger and step though the button code.

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

Posted: Thu Sep 20, 2018 5:50 am
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.

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

Posted: Mon Sep 24, 2018 1:25 am
by simon.briggs
Tried running through debug, nothing is coming up in the debug console. Apologies if I am missing something.

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

Posted: Mon Sep 24, 2018 2:51 am
by jvierra
What did you expect? Did you get to a breakpoint? Do you understand how to use the debugger in PSS?

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

Posted: Mon Sep 24, 2018 4:57 am
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.

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

Posted: Mon Sep 24, 2018 5:01 am
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.