Having Trouble Passing Vars between forms

时间:2016-08-31 18:28:19

标签: powershell powershell-remoting

im working in powershell studio im trying to pass a string from mainform to secondform and the var stays empty

[MainForm]

Param (
                        [Parameter(Mandatory=$false)]
                        [String]$computer,
                        [String]$UserName
)


$OnLoadFormEvent={
#TODO: Initialize Form Controls here
#          try{
#          Import-Module ActiveDirectory
#          }
#          catch{
#                      $ErrorMessage = $_.Exception.Message
#                      [System.Windows.Forms.MessageBox]::Show($ErrorMessage) 
#                      }

}

#
##region Control Helper Functions
#
#endregion

$buttonOK_Click={
            #TODO: Place custom script here

            if ($checkboxComputer.Checked) {
                        $computer = $textboxinput.Text
                        Call-Computer_Form_pff

            }         
            if ($checkboxUser.Checked){
                        $UserName = $textboxinput.Text
                        Call-User_Form_pff
            }
            else{
                        $ErrorMessage = "You Must Select At Least One Checkbox"
                        [System.Windows.Forms.MessageBox]::Show($ErrorMessage) 
                        }


}


[SecondForm]
$FormEvent_Load={
            #TODO: Initialize Form Controls here
            try {
            Call-MainForm_pff -computer $Computer
            $computerSystem = get-wmiobject Win32_ComputerSystem -ComputerName $Computer
}
catch{
                        $ErrorMessage = $_.Exception.Message
            Write-Host $ErrorMessage
#                      #[System.Windows.Forms.MessageBox]::Show($ErrorMessage) 
            }
}

from what i read it should work when i put in on the mainform's param section and call it this way from secondform: Call-MainForm_pff -computer $Computer

can anyone help me with this?

0 个答案:

没有答案