Worklet: Automatic OS Upgrade to Windows 10 1909

You are very welcome! Glad this will give you some time back in your day to focus on more important things. The upgrade time really depends on how old the current OS. For devices running 1903, it took about 20-35 minutes from start to finish for the Worklet to upgrade a device.

Ran this today and still had the iso under amagent/Windows1909OSUpgrade.iso after the installation finished. Tracked it down and the quotes when copied from the script in the first line of the evaluation aren’t safe. Be sure to change the quotes if you copy this section of code:

For whatever reason the quotes were “fancy” and I ended up having to change them out with normal quotes.

When I ran it on a device, it upgraded from 1903 to 1909 in just under 22 minutes with zero intervention. When I ran it the second time to see if it would evaluate correctly, it reinstalled 1909.

Thanks for the heads up @ews - I’ll let @awhitman know to come take a look.

Thanks for finding this. and sharing!

I am not sure why this is not working for you. The single quote vs the double quote should not matter in this scenario. The only difference in single and double quotes in PS is that a double quote is Powershell reads every character in the string, and looks for characters that can be substituted for a variable defined outside the string. Since there is no variable, or PS operation between the double quotes, it just reads it as a normal string. I will test this further and see if I can reproduce it. however, I am glad this change got it working for you!

22 minutes is about what I see as well. The reason the upgrade ran again on the device is because you manually executed the policy on the device, which skips evaluation, and runs the remediation code immediately on the device(s). The Evaluation code of the Worklet is ran every time a device rescan takes place, either manually, or on the rescan schedule of the Group. The evaluation results determine if remediation needs to run when the policy is scheduled for execution, and also marks the policy for the device as “pending” or “compliant”

A Worklet will automatically rescan a device once it completes running on the device in order to determine if the device is compliant after remediation. If you want to determine the results of evaluation code on a device, all you need to do is rescan the device and see if the policy marks it as “pending”, or "complaint.

Let me know if you have any further questions.


1 Like

@awhitman - thanks for following up on this. I read the manual execution and skipping the evaluation and it didn’t even click. Thanks for the explanation.

Here’s more detail to the issue I experienced:

Using Chrome 81.0.4044.113, this is how the code block appears on screen:

Notice the “fancy” quotes.

When you copy the code (using the “copy to clipboard” widget) and paste into automox, it keeps the “fancy” quotes, which does not properly enclose the string, which means it isn’t being evaluated correctly:

If I change the quotes to either single or double, it properly encloses the string (the text turns green):
Single Quotes

Double Quotes

Same issue in Firefox 75.0

Just an oddity… not sure why it is happening.

1 Like

I can concur with this…
Mine acted the same way. It was not deleting the iso. in fact some of my 1903’s were doing the same thing, and I checked the “fancy” quotes, and they were there as well. Changed to regular quotes and the string enclosed properly. Haven’t checked if the iso deleted or not, but I’m guessing it probably did, since yours did.


Thanks so much for noticing this! It must be the way I moved it into the community post. The one in my Github that I used to post this is using double quotes.

I have made the appropriate change to the original code post for both 1909, and 1903.

Thanks again!

1 Like

Thanks for figuring this out @ews - I gave you the community bug finder badge for giving us the solution!


We haven’t had much luck getting this to work. Checking the activity log we see the following. When I search for the c:\windows\temp\output.csv file referenced one does not exist. Any ideas on how best to identify our issue?

You cannot call a method on a null-valued expression. At C:\ProgramData\amagent\execDir807239699\execcmd579763798.ps1:41 char:25 + $objs | Foreach-Object {$.href = ($.href).Replace(‘amp;’,’’)} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull C:\ProgramData\amagent\execDir807239699\execcmd579763798.ps1 : .iso linked was successfully created but download Failed. Reference c:\windows\temp\output.csv for more information or contact Automox Support + CategoryInfo : NotSpecified: (:slight_smile: [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,execcmd579763798.ps1

Sorry about that. I’ve notified @awhitman to come take a look and see if he can figure out where it’s failing.


Take the remediation code and try running it directly on a device. It looks like the download link is failing, so I wonder if it has something to do with the Worklet being executed remotely.

Copy the remediation into a x86 Powershell ISE admin session directly on one of the devices and see if it errors out there as well. I tested it and it worked for me.

Wow, for the first time in my life I found an active discussion about the same issue I am experiencing. Amazing

I am doing a trial of Automox and experiencing the same issue Chris_2.0 is seeing. I just tried your recommendation awhitman - running the remediation code manually in Powershell and low and behold the .ISO file is actually downloading now.

I’m not sure what this means for deploying it as intended?

1 Like

Unfortunately it errors out locally for me as well

You cannot call a method on a null-valued expression.
At line:40 char:25

  • $objs | Foreach-Object {$.href = ($.href).Replace(‘amp;’,’’)}
  •                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

@Ckraem608 Did you have to make any adjustments to the remediation code to run it locally or does it work as posted above?

Chris - I did not make any adjustments, just copied the code and pasted into x86 Powershell ISE. The download started right away. Unfortunately I did get a pop-up on that machine from UAC asking me to confirm I wanted to make changes. Afterwards it installed and rebooted automatically. Hopefully I can figure it out so it is seamless.

I copied the code from the blog post not this post though.

I think the code in this topic has been updated since the blog post was made, so you’ll want to use the top post which @awhitman keeps updated, rather than the blog post.

1 Like

I need to give this another go as tried a few weeks ago and ISO downloaded but install didn’t happen. Need to work through why.

@trilly what happens when you take the remediation code and try to run it locally on the device using Powershell x86 ISE? It will probably throw and error that we can look at to help root cause this.

1 Like

@awhitman, I’ll do that, run in Powerhsell that is, missed that trick when looking at it last time, obvious thing to try!

sounds good! Send me the error that you see and I will help you through it.

Have a good weekend!