0

I have a Powershell script using the Get-QADUser cmdlet several times. This cmdlet is reporting progress with a progress bar.

So, let's consider this script,

$user = Get-QADUser "User1"
$user = Get-QADUser "User2"
$user = Get-QADUser "User3"
$user = Get-QADUser "User4"

If we consider that each statement represents 25% of my total script execution time (no need to be exact), I'd like to Write-progress based on these cmdlets' progress. In other words, this would represent a global progress bar for the script.

So, if $user = Get-QADUser "User1" is at 50% progress, I'd like to report ~13% (50% of 25%). My problem is, I don't if it's possible to have access to the Get-QADUser progress in live time.

Is their a way to call Write-Progress -PercentComplete based on a third party cmdlet in Powershell ?

1 Answer 1

1
$users_added = @()
$users = @('User1', 'User2', 'User3', 'User4')

Write-Progress -Activity 'Create User' -ID 1 -PercentComplete 0

for ($i = 0; $i -lt $users.count; $i++ ) {
    Write-Progress -Activity 'Create User' -ID 1 -PercentComplete $($i / $users.count * 100)
    $users_added += Get-QADUser $users[$i]
}
Sign up to request clarification or add additional context in comments.

1 Comment

The problem I see with this approach is that Get-QADUser $users[$i] can return more than one user. In this case my progress won't be representative. This is why I wanna based my Write-Progress on the actual progress status of the cmdlet if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.