在wpf按钮上单击调用多个函数

时间:2016-11-17 08:49:41

标签: wpf powershell

是否可以通过点击按钮调用多个功能?

例如,我得到了这个:

function environmentTemp(){
if($checkbox_1.Checked){


}
if($checkbox_2.Checked){}


}
if($checkbox_3.Checked){



}

和此:

function create(){
$UserList = Import-Csv -Path $txt_csv.Text -Delimiter ";"

<# ------- CREATE USERS ------- #>
foreach ($User in $UserList) {

    $OU = $User.path
    $UPN = $User.UPN
    $Password = $User.password 
    $Detailedname = $User.firstname + " " + $User.Lastname 
    $UserFirstname = $User.Firstname 
    $FirstLetterFirstname = $UserFirstname.substring(0,1) 
    $SAM =  $User.UPN
    $Company = $User.company
    $Description = $User.description
    $AccountExpirationDate = $User.accountexpirationdate

    $params = @{ 'Name'=$Detailedname;
                 'SamAccountName'=$SAM;
                 'UserPrincipalName'=$UPN+'@test.nl';
                 'DisplayName'=$Detailedname;
                 'GivenName'=$UserFirstname;
                 'Surname'=$User.Lastname;
                 'AccountPassword'=(ConvertTo-SecureString $Password -AsPlainText -Force);
                 'Enabled'=$True;
                 'PasswordNeverExpires'=$True;
                 'Path'=$OU;
                 'Company'=$Company;
                 'Description'=$Description;
                 'AccountExpirationDate'=$AccountExpirationDate                 
                }

    New-ADUser @params
}
}

这是我的Wpf按钮对象:

$button_add.Add_Click({create})

用户可以选择环境。当我点击创建按钮时,我想同时执行函数environmentTemp和Create,或者是否可以将复选框的选项存储到变量中?

1 个答案:

答案 0 :(得分:0)

您可以使用分号 分隔语句

$button_add.Add_Click({create; environmentTemp})