# Manually update

**URL:** <https://forums.powershell.org/t/manually-update/18552>\
**Category:** PowerShell Help\
**Created:** [February 10, 2022, 10:04pm UTC](https://forums.powershell.org/t/manually-update/18552 "2022-02-10T22:04:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![brad-sam](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@brad-sam](https://forums.powershell.org/u/brad-sam)\
**Post date:** [February 10, 2022, 10:04pm UTC](https://forums.powershell.org/t/manually-update/18552/1 "2022-02-10T22:04:55Z")

</div>

Hi All,  
I try create manual update script to install .msu files for multiple Windows ver.  
I run this from usb with .bat file, script exit with out any error but nothing installed  
Please, help  
Thanks.

```auto
$currentLocation = Split-Path -parent $MyInvocation.MyCommand.Definition
$OSmBuild = (Get-WmiObject Win32_OperatingSystem).Version

# Update Directory Location
$updatedir_1507 = "Updates\version_1507"
$updatedir_1511 = "Updates\version_1511"
$updatedir_1607 = "Updates\version_1607"

if($OSmBuild -like '10.0.10240')
{
  
$updatedir = "$currentLocation\$updatedir_1507"

$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}

foreach ($msu in $msus)
{
    write-host "Installing update $msu ..."
    $fullname = $msu.fullname
    $fullname = "`"" + $fullname + "`""
    $parameters = $fullname + " /quiet /norestart"
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    write-host "Finished installing $msu"
}

write-host "Restarting Computer"
#Restart-Computer

### Windows_10_version_1511 ###

    ElseIf($OSmBuild -like '10.0.10586')
    {
       
$updatedir = "$currentLocation\$updatedir_1511"

$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}

foreach ($msu in $msus)
{
    write-host "Installing update $msu ..."
    $fullname = $msu.fullname
    $fullname = "`"" + $fullname + "`""
    $parameters = $fullname + " /quiet /norestart"
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    write-host "Finished installing $msu"
}

write-host "Restarting Computer"
#Restart-Computer
}

 ### Windows_10_version_1607 ###

    ElseIf($OSmBuild -like '10.0.14393')
    {
        $updatedir = "$currentLocation\$updatedir_1607"

$files = Get-ChildItem $updatedir -Recurse
$msus = $files | ? {$_.extension -eq ".msu"}

foreach ($msu in $msus)
{
    write-host "Installing update $msu ..."
    $fullname = $msu.fullname
    $fullname = "`"" + $fullname + "`""
    $parameters = $fullname + " /quiet /norestart"
    $install = [System.Diagnostics.Process]::Start( "wusa",$parameters )
    $install.WaitForExit()
    write-host "Finished installing $msu"
}

write-host "Restarting Computer"
#Restart-Computer
}
Else
{
 Write-Host "Windows 7 or XP"
}

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 10, 2022, 11:07pm UTC](https://forums.powershell.org/t/manually-update/18552/2 "2022-02-10T23:07:37Z")

</div>

Brad,  
Welcome back to the forum. 👋🏽

It sounds weird that you don’t get any errors since there 's a closing culry brace missing after your first `Restart-Computer` command.

Regardless of that … since the only difference between your if conditions is the source path you can write your code much less repetitive like this:

```auto
[cmdletbinding()]
Param()
$OSmBuild = (Get-CimInstance -ClassName CIM_OperatingSystem -Verbose:$false ).Version 
Write-Verbose "detected version: '$($OSmBuild)'"
switch ($OSmBuild) {
    '10.0.10240' { $Path = Join-Path -Path $PSScriptRoot -ChildPath 'Updates\version_1507' }
    '10.0.10586' { $Path = Join-Path -Path $PSScriptRoot -ChildPath 'Updates\version_1511' }
    '10.0.14393' { $Path = Join-Path -Path $PSScriptRoot -ChildPath 'Updates\version_1607' }
    Default { $UnsupportedOS = $true }
}
if (-not $UnsupportedOS) {
    $MsuList = Get-ChildItem -Path $Path -Filter '*.msu' -File -Recurse
    foreach ($Msu in $MsuList) {
        Write-Verbose "Installing update $msu ..."
        Start-Process -FilePath 'wusa.exe' -ArgumentList "$($Msu.FullName) /quiet /norestart" -Wait
        Write-Verbose "Finished installing $msu"
    }
    Write-Verbose "Restarting Computer ..."
    Restart-Computer -Confirm
}
else {
    Write-Verbose 'Unsupported OS ... '
}

```

With the `[cmdletbinding]` at the top of your script and using `Write-Verbose` instead of `Write-Host` it does not output unnecessary messages until you run it with the parameter `-Verbose`. If you tested the script successfully of course you can remove the parameter `-Confirm` from the `Restart-Computer` command. 😉

Regardless of that … are you really still working with WIndows 10 1507, 1511 or 1607?? The support for those already ended years ago. You should not run those Windows versions anymore in any production environment!!!

---

<div class="post-metadata">

**Author:** ![brad-sam](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@brad-sam](https://forums.powershell.org/u/brad-sam)\
**Post date:** [February 11, 2022, 3:53pm UTC](https://forums.powershell.org/t/manually-update/18552/3 "2022-02-11T15:53:41Z")

</div>

Hi Olaf,

Thank you for your help  
Look like all working correct, BUT nothing installed  
This old systems just for the test, i also try update 1909 with latest .msu, script finish no errors but i not see new KB installed

Thanks for your help as always 🤝

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [February 14, 2022, 7:46pm UTC](https://forums.powershell.org/t/manually-update/18552/4 "2022-02-14T19:46:33Z")

</div>

I wrote a script a while back to do pretty much what you are doing. I chose a slightly different approach as my script was designed to install ANY updates in a specific folder be they .EXE, .CAB or .MSU. The only thing I can see that I did differently was defined the full path to WUSA.exe. Have you tried that?

```auto
$WSU = "$($ENV:SystemRoot)\System32\Wusa.exe"
$cmdToExec = 'Start-Process -FilePath $WSU -ArgumentList ($($Msu.FullName), /quiet, /norestart) -Wait'
Invoke-Expression $cmdToExec

```

Another option I chose to use to help in troubleshooting was to add a logfile.

```auto
$WusaLog = Join-Path $ENV:Temp "$($Wsu.Name).evtx"
$LogArg = "/log:$WusaLog"
$cmdToExec = 'Start-Process -FilePath $WSU -ArgumentList ($($Msu.FullName), /quiet, /norestart, $LogArg) -Wait'
Invoke-Expression $cmdToExec

```

---

<div class="post-metadata">

**Author:** ![brad-sam](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@brad-sam](https://forums.powershell.org/u/brad-sam)\
**Post date:** [February 16, 2022, 9:29pm UTC](https://forums.powershell.org/t/manually-update/18552/5 "2022-02-16T21:29:42Z")

</div>

Hi tonyd,  
Thank you for your exemple,  
Olaf script and your working perfect  
it was my mistake, i downloaded comulative updates but tottaly forget download stack updates  
but now look like all working perfect , but script stop in one point and in EventLog i see this message:  
“A reboot is necessary before package KB5009545 can be changed to the Installed state.”  
How i can continue process and reboot in the end when all .msu installed  
also,  
Do you mind to share your code how to install mix files( .EXE, .CAB or .MSU)  
Thanks

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:19pm UTC](https://forums.powershell.org/t/manually-update/18552/6 "2024-05-16T20:19:31Z")

</div>


