I have MSU,MSI,MSP,exe files all downloaded in common shared location i need to install all files in multiple remote server 2012,2016,2019

D Vijayakumar VLR 126 Reputation points
2022-01-14T11:49:12.767+00:00

Hi All,

I have few MSU, MSI, MSP, exe files all saved in common location, I need to install all this in multiple remote servers OS 2012, 2016, 2109 through powershell scripts, I tried some sripts from interent files copied from source to destination but patches not able to install i need on this please suggest or guide me to learn more, Once patches installation completed file need to remove after or before reboot, required output ServerName, KBArticel number, Installed by, Installed on CSV file.

$Servers = Get-Content -Path "c:\Temp\Servers.txt"
$Source = "\Server\d$\Patching\January\ (This path we have all server os patches) 2012,2016,2019
$dest = "c$\Temp\Patches"
$updates =Get-ChildItem -Path $Source | Where-Object {$_.Name -like ".MSU",".MSP","*.MSI"}
foreach ($server in $Servers) {
if (test-Connection -ComputerName $Server -quiet) {
copy-Item $Source -Destination \Server\$dest -Recurse -Force
if(Test-Path -Path $updates) {
foreach ($update in $updates) {
$updatefilepath = $update.fullname
Write-Host "Patches Installation started $update $server"
Invoke-Command -ComputerName $server -ScriptBlock {start-process -wait -wusa -Argumentlist "/update $updatefilepath","/quiet","/norestart"}
}
{
Write-Host "Patching Installation completed successfull on $server" -foregroundColor -Green
} else {
Write-Host "Patches Not Installed unsuccessfull on $server" -foregroundColor -Red
}
}
}
}
Get-Hofix > "c:\Temp\New-HotFix_Installed_List.txt"

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,920 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,507 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 39,591 Reputation points
    2022-01-21T09:01:52.817+00:00

    Hello VijayakumarD,

    Thank you for your question and reaching out.

    I can understand you are facing issues while installing Windows update using script.

    I believe you need to take different approach for each file type of update as they have different behavior and different methods to install.

    For Example :
    A. For .msu package type you need to use wusa.exe
    B. For .msi and .msp package type you need use msiexec.exe

    Hence in your case you can create folder for each of file package type and call from your script using wusa.exe or msiexec.exe

    I would also suggest you to use WSUS to push updates which should be easy to use and manageable.

    You can also consider third party tool called batchpatch dot com


    --If the reply is helpful, please Upvote and Accept as answer--


  2. D Vijayakumar VLR 126 Reputation points
    2022-02-06T05:11:47.437+00:00

    Hi
    Thanks for your update, I tried with this below mention script but i got error unable to install windows upadte can you please checka nd help on this issue.

    $Servers = Get-Content -Path "C:\Temp\Patch\serverlist.txt"
    $Source = "\Server\D\Patching\feb22\win2012\"
    $Dest = "C$\Temp\Patch\"
    $Testpath = "\Server\D\Patching\feb22\win2012\"
    foreach ($Server in $servers) {
    if (test-Connection -ComputerName $Servers) {
    Copy-Item $Source -Destination \$server\$dest -Rescurse -Force
    if (Test-Path -Path $testpath) {
    Write-Host "Patches Installing on $server"
    Invoke-Command -ComputerName $server -ScriptBlock {(&cmd.exe /c or Powershell.exe wusa.exe /I "C:\Temp\Patch\Windows8.l-kb5008603-x64_58f1b60cb6250c4fb1e2d4c86o16eeef71ce6d1e.msu",
    "windows8.1-kb5010215-x64_Oeclcede5ece93cee398a2366c6a6489627030.msu" /Quiet /norestart)}
    Write-Host "Patch Installation Completed Successfully on $server" -ForegroundColor Green
    }
    } else {
    Write-Host "Patch Installation Failed, $Server not reachable or not online" -ForegroundColor Red
    }
    }

    in c temp inside patch folder create and files copied by script, But not installed try to install patch got failed ( I tried both &cmd.exe /c and powershell.exe) i checked in event viewer below error shown

    Windows update could not be installed of error 2147942402 "The System cannot find the file specified."(Command line ""C:\Windows\System32\wusa.exe" /I "C:\Temp\Patch\Windows8.l-kb5008603-x64_58f1b60cb6250c4fb1e2d4c86o16eeef71ce6d1e.msu",
    "windows8.1-kb5010215-x64_Oeclcede5ece93cee398a2366c6a6489627030.msu" /Quiet /norestart)}.

    1. While i try to install windows update patch got failed facing error (I tried both &cmd.exe /c and powershell.exe) i checked in event viwer below error shown, but mentioned path kb article files availble in location

    Windows update could not be installed of error 2147942402 "The System cannot find the file specified."(Command line ""C:\Windows\System32\wusa.exe" /I "C:\Temp\Patch\Windows8.l-kb5008603-x64_58f1b60cb6250c4fb1e2d4c86o16eeef71ce6d1e.msu",
    "windows8.1-kb5010215-x64_Oeclcede5ece93cee398a2366c6a6489627030.msu" /Quiet /norestart)}

    1. I have Multiple OS 2012,2016,2019 and more KB Articles have in common path that all how can i install thorugh scripts (.msu,.msi,.msp,.exe) (.msu and .msi,.msp and .exe which one required to install patch like wusa.exe or msiexec.exe)
    2. Common path i have more files but i need to install few updates only like i have 7 or 8 patches,But i want to install 3 patches only that how can i install.
    3. I required out put details in csv or html file which patch got installed and which patch got not installed or failed on server wise with kb article details.
    0 comments No comments

Your answer

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