Warning status - Job status

Product: PowerShell Universal
Version: 2.4.0

Hi,

We loop through 1-2000 objects every hour, and some of these objects should return an warning. An simple example:

$Users = Get-ADUser -Filter * -Properties mobile
foreach ($user in $Users) {
    if (!($user.mobile -eq $null)) {
        #Process the user
    }
    else {
        Write-Warning "The user does not have an mobile number defined"
    }
}

If executed manually, the warning is shown in the output. But i cant get PSU Job status to show it.
I can only set it to throw, and that terminates the entire script.

Is there an option to accomplish this?

How about using “Write-Output”? I feel like that oughta Work.

Hi,

We already use Write-Output for the info messages.
But we use the “throw” function in Powershell, to get the Jobs to report an error in status section.
Like this:

try {
      Get-ADUser -Identity "SomeFakeName" -erroraction stop
}
catch {
      throw "Failed to lookup the user - $($_.Exception.Message)"
}

That way the job is terminated, and its status is set to failed.
We would like an similar option, for the Warning messages.

We currently don’t have a warning state for the entire job state. You should be able to see warnings in the job log but it won’t be visible in the job table. I think it’s a good idea to add some sort of option that allows this. I’ve opened this issue to track: Job Warning State · Issue #627 · ironmansoftware/issues · GitHub

Awesome! :slight_smile:
Looking forward to this new feature