Detect Windows 10 Version and update to latest build via powershell

Anonymous
2021-04-18T08:36:37.523+00:00

Hi

Im looking for a script if someone has made it that will check the windows build.
If it's less than 19042.572 then do the following:

Something Like

If

(Get-CimInstance Win32_OperatingSystem).BuildNumber < 19042 then

Set-ExecutionPolicy unrestricted

Install-Module PSWindowsUpdate

Import-Module PSWindowsUpdate

Get-WindowsUpdate -KBArticleID KBXXXXXX (This being the Latest Windows 20H2)

Install-WindowsUpdate -AcceptAll -AutoReboot

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-04-19T03:36:37.493+00:00

    Hi,

    The comparison operator in PowerShell is "-lt", not "<" and you should specify the if block using the curly braces.

    if((Get-CimInstance Win32_OperatingSystem).BuildNumber -le 19042)  
    {  
        Set-ExecutionPolicy unrestricted  
        Install-Module PSWindowsUpdate  
        Import-Module PSWindowsUpdate  
        Get-WindowsUpdate -KBArticleID KBXXXXXX -Install -AcceptAll -AutoReboot  
    }  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.