New filters on the Home Feed, take a look!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

6
Question about Start-Job
Post Body

Hi /r/powershell,

I have a simple script logic that narrows down to this:

Function Set-Object {
    $Object.Status = 'Altered'
}

$Object = [PsCustomObject] @{
    'Status' = $null
}

Set-Object

$Object

The result is:

Status 
------ 
Altered

Now I thought I can start the Set-Object as a background job using Start-Job and periodically check $Object for changes. I thought I can just do this with Start-Job -ScriptBlock {Set-Object} which results in:

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
--     ----            -------------   -----         -----------     --------             -------                  
1      Job1            BackgroundJob   Running       True            localhost            Set-Object  

But when I check $Object for changes, I can't see any. When I check the status of the job with Get-Job, it has failed:

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
--     ----            -------------   -----         -----------     --------             -------                  
1      Job1            BackgroundJob   Failed        False           localhost            Set-Object     

Why did the job fail?

Author
Account Strength
90%
Account Age
15 years
Verified Email
Yes
Verified Flair
No
Total Karma
4,540
Link Karma
3,347
Comment Karma
1,193
Profile updated: 4 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 years ago