POSH-SSH module is not functioning from a button press on a form
Posted: 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.
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
}