Update-Jobtracker help

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Update-Jobtracker help

Post by dlaurora »

Hello everyone,

I trying to learn how to use the Job tracker function, till now what I did is to create the job, also was able to add arguments into it, but i'm not sure how to update it.

The below script it suppose to do an AD search, and update a combobox with users name, it partially works, sometimes it update it and sometimes it gets stuck, and I think it is case I don't stop the job or update it, so i went to the example that it is posted in responsive form page, tried to replicate it but did not work, could you please help me with it?

Thanks, best regards.

Code: Select all

[$textboxFind_TextChanged= {
#TODO: Place custom script here
$JobTrackerList = New-Object System.Collections.ArrayList

if ($textboxFind.Text.Length -gt 2)
{
Update-Combobox -ComboBox $textboxFind -Items ""
$textboxFind.SelectionLength = 0
$textboxFind.SelectionStart = $textboxFind.Text.Length
$ArgumentList = $textboxFind.Text
$loadplane.Visible = $true

Add-JobTracker -Name "ADuser" `
-JobScript {

Param ($ArgumentList)
$global:progresspreference = 'SilentlyContinue'
Get-ADUser -ResultSetSize 6 -Filter { (GivenName -like $ArgumentList) -or (sn -like $ArgumentList) } -Properties PasswordLastSet, SamAccountName

} -ArgumentList $ArgumentList `
-CompletedScript {

Param ($Job)
$Global:Users = Receive-Job -Job $Job

If($global:users -eq $null) {$textbox.Text = "no funciono"} Else { $textbox.Text = $Global:Users}

Update-Combobox -Items $Global:Users.SamAccountName -ComboBox $textboxFind -Append
$loadplane.Visible = $false
} `
-UpdateScript {
Param ($Job)
$results = Receive-Job -Job $Job | Select-Object -Last 1

}

}
Else { $loadplane.Visible = $false }]
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update-Jobtracker help

Post by jvierra »

This would be closer to what you want:

Code: Select all

$textboxFind_TextChanged = {
    
    if ($textboxFind.Text.Length -gt 2) {
        
        $textboxFind.SelectionLength = 0
        $textboxFind.SelectionStart = $textboxFind.Text.Length
        $ArgumentList = $textboxFind.Text
        $loadplane.Visible = $true
        
        Add-JobTracker -Name ADuser -ArgumentList $ArgumentList `
            -JobScript {
                Param ($ArgumentList)
                $global:progresspreference = 'SilentlyContinue'
                Get-ADUser -ResultSetSize 6 -Filter "GivenName -like '$ArgumentList*' -or sn -like '$ArgumentList*'" -Properties PasswordLastSet, SamAccountName
                
            } `
            -CompletedScript {
                Param ($Job)
                $users = Receive-Job -Job $Job
                
                if ($users) {
                   $textbox.Text = $Global:Users 
                } else {
                   $textbox.Text = "no funciono"
                }
                
                Update-Combobox -Items $Global:Users.SamAccountName -ComboBox $textboxFind -Append
                $loadplane.Visible = $false
            } `
        -UpdateScript {
            Param ($Job)
            $results = Receive-Job -Job $Job | Select-Object -Last 1
        }
    }
    
}
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Re: Update-Jobtracker help

Post by dlaurora »

Thanks for the reply,

It is working but with some error that i have to check.

One last question, if you see I only do the task if the word written on the text box is greater than 2, do this, do I have to create a stop job each time that we write a letter? For example:

$textbox = "jho" , here it supposes to bring me the first 6 users that contain "jho" on it, but when I add the next letter, "jhon", the result is $null and the combobox is not updated

#
ERROR: Update-ComboBox : Cannot validate argument on parameter 'Items'. The argument is null. Provide a valid value for the argument, and then try running the
ERROR: command again.
AD Tool V 1.0.psf (203, 27): ERROR: At Line: 203 char: 27
ERROR: + Update-Combobox -Items $Users.SamAccountName -ComboBo ...
#
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update-Jobtracker help

Post by jvierra »

You must always start a new job. Using a job here is not a good idea.
User avatar
dlaurora
Posts: 31
Last visit: Wed Oct 02, 2019 12:51 pm

Re: Update-Jobtracker help

Post by dlaurora »

thanks, I'll try to find another way to make it responsive, I was trying to populate a variable at the start of the form with users but get-aduser -filter * -properties SamAccountName takes to long and the variable is always empty till it finishes.
This topic is 5 years old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked