Skip to main content

Hi Ya’ll



Big Shoutout and thanks to @rich for getting the information needed in order for this script to work successfully!



This is a one-click automatic upgrade without needing to pre-deploy the 1909 .iso image to your devices. This Worklet will automatically build out the download link for 1909 based on your OS’s architecture, download the .iso image to you local system, mount the .iso to a disk drive, and then automatically run the download setup all silently without any user interaction. It will remove the iso after the installation completes.



The Evaluation and Remediation code for the Worklet is as follows:



Evaluation:



$iso = "C:\programdata\Windows1909OSUpgrade.iso"



if ((Test-Path $iso) -eq $true)

{Remove-Item $iso

}



$osversion = (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')



if (($osversion -lt "1909"))

{exit 1

}

else

{exit 0

}



Remediation:



$lang = "English"

$locID = "en-US"

$verID = "Windows10ISO"

$skuID = "9029"

$prodID = "1429"

$archID = "IsoX64"



## variables you might not want to change (unless msft changes their schema)

$pgeIDs = @("a8f8f489-4c7f-463a-9ca6-5cff94d8d041", "cfa9e580-a81e-4a4b-a846-7b21bf4e2e5b")

$actIDs = @("getskuinformationbyproductedition", "GetProductDownloadLinksBySku")

$hstParam = "www.microsoft.com"

$segParam = "software-download"

$sdvParam = "2"



## used to spoof a non-windows web request

$userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362"



## used to maintain session in subsequent requests

$sessionID = Dguid]::NewGuid()



## builds session request url

$uri = "https://www.microsoft.com/" + $locID + "/api/controls/contentinclude/html"

$uri += "?pageId=" + $pgeIDse0]

$uri += "&host=" + $hstParam

$uri += "&segments=" + $segParam + "," + $verID

$uri += "&query="

$uri += "&action=" + $actIDst0]

$uri += "&sessionId=" + $sessionID

$uri += "&productEditionId=" + $prodID

$uri += "&sdvParam=" + $sdvParam



## requests user session

Invoke-WebRequest -UserAgent $userAgent -WebSession $session $uri -ErrorAction:Stop -Method:Post -Headers $headers -UseBasicParsing | Out-Null



## builds link request url

$uri = "https://www.microsoft.com/" + $locID + "/api/controls/contentinclude/html"

$uri += "?pageId=" + $pgeIDse1]

$uri += "&host=" + $hstParam

$uri += "&segments=" + $segParam + "," + $verID

$uri += "&query="

$uri += "&action=" + $actIDst1]

$uri += "&sessionId=" + $sessionID

$uri += "&skuId=" + $skuID

$uri += "&lang=" + $lang

$uri += "&sdvParam=" + $sdvParam



## requests link data

$response = Invoke-WebRequest -UserAgent $userAgent -WebSession $session $uri -ErrorAction:Stop -Method:Post -Headers $headers -UseBasicParsing



## parses response data

$objs = $response.Links

$objs | Foreach-Object {$_.href = ($_.href).Replace('amp;','')}

$linky = $objs | Select-Object -Property href | Sort-Object -Property href

$link = $linky | Select-Object -ExpandProperty href



## Determine correct link for OS Architecture

$osarch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture

If ($osarch -eq "64-bit") {

$dllink = $link | Where-Object {$_ -match 'x64.iso'}

} elseif ($osarch -eq "32-bit") {

$dllink = $link | Where-Object {$_ -match 'x32.iso'}

}



Write-Output $dllink



Try {

(new-object System.Net.WebClient).DownloadFile("$dllink", "C:\programdata\Windows1909OSUpgrade.iso") |

Out-file C:\Windows\Temp\output.csv -Append

} Catch {

Write-Error ".iso linked was successfully created but download Failed. Reference c:\windows\temp\output.csv for more information or contact Automox Support"

exit 1

}



#specify path to ISO image

#############Change the settings in this block#######################

$isoImg = "C:\programdata\Windows1909OSUpgrade.iso"

##############################################################







Mount-DiskImage -ImagePath $isoImg

$letter = (Get-DiskImage $isoImg | Get-Volume).DriveLetter

$dos = ":" ### Unnecessary with changed line below

$drivemount = "$letter" + "$dos"

Set-Location $drivemount



# Required: The drive letter needs to be manually changed to match the value of $driverletter (ex: Y:)



# Optional: /pkey is for a device that needs a product key. Default is disable, remove "#" to enable. (ex: /pkey XXXXX-XXXXX). Not required for install



# Optional: /noreboot is enabled by default. Remove "#" to automatically reboot the device after install is complete



./setup.exe /auto upgrade /quiet #/pkey



The Evaluation code exits with a 1 if a devices OS version is less than 1909 and executes the policy at the scheduled time



Choose the setup.exe arguments you want when it performs the OS update. This is the last line of code in the Remediation block. By Default it is set to do a quiet install and automatically reboot the device to complete the upgrade.



Here is an example of the setup.exe command using the /quiet and /noreboot argument:



Copy to clipboard



.\setup.exe /auto upgrade /quiet /noreboot



That should do it! Be sure to test this on a few devices before deploy to production environment.



Let me know if there are any questions!

@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!


Will there be a worklet soon for 2004?


Hi Allan,



This is being worked on as we speak and will be available soon.



Thanks


@awhitman – thanks for getting back to me. That’s great news!


@awhitman you might want to check out my companies github repo







Ive updated my original function to grab the latest ISO download link instead of a hard-coded copy. I think it relies on powershell 5 code so it no longer works on macOS and linux but it could probably be modified to do so if thats your thing. And as long as MSFT doesnt change the schema it will always grab the latest version available. In addition to that there’s also a function that does the ISO download, mounting and install for you all in one step.



Theres also function that uses the windows update assistant exe file to silently upgrade as well. This is our preferred method over the ISO install. The reboot to apply the update is shorter meaning less downtime for the user.



Finally, theres a function that installs the 1903>1909 enablement package. These are super fast to apply. If MSFT releases one for 2004, we will update the function, as this is the smoothest way to upgrade windows yet.


wow, thanks so much once again for this!! I will be sure to start testing this to see how it works in my environment!


With 2004 out, does this still work?


Don’t think so, I haven’t been able to get the download link working. Seems MS have removed/changed it.


I was looking for the 1909 ISO download path separately for another task, and I couldn’t find it. I bet you are correct.


Reply