将函数连接到 powershell studio 中的进度条

Connect a function to progess-bar in powershell studio

有没有一种方法可以将函数连接到进度条对象?

$buttonAdd_Click = {
    create
    $loadingbar.Refresh
}

这是我的按钮对象。变量 `$loadingbar 是我的 progess-bar 对象。

这是我的创建函数:

function create()
{

    $wshell = New-Object -ComObject Wscript.Shell
    $UserList = Import-Csv -Path $txt_csv.Text -Delimiter ";" | Select-Object -ExpandProperty UPN   


<# ------- 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 + '@ib.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
    }
    }`

问题:当我点击按钮时,我想在加载栏中看到创建函数的进程。我该怎么做?

另一个问题:Powershell studio中的progessbar和progress baroverlay有什么区别?

我刚刚解决了这个问题。我只使用 hard-coded 值来查看我的加载栏是否正常工作。例如,在方法的开头我使用 $loadingbar.value = 50;,最后我使用 $loadingbar.value = 100;。有点脏代码,但所有者很满意。