How to Install patches using PowerShell?

 To install patches using PowerShell, you can utilize the `Install-Package` cmdlet or `Start-Process` cmdlet with appropriate parameters. Here's an example of how you can use PowerShell to install patches:




# Install specific Windows update by KB number

$KBNumber = "<KB_Number>"

Start-Process -FilePath "wusa.exe" -ArgumentList "/quiet /norestart <path_to_kb_file.msu>" -Wait


# Install updates from Microsoft Update

Install-Package -Name "<Package_Name>" -Source "MicrosoftUpdate"


# Install updates from a local folder

$FolderPath = "<Path_to_Patches_Folder>"

$PatchFiles = Get-ChildItem -Path $FolderPath -Filter "*.msu" -File

foreach ($PatchFile in $PatchFiles) {

    Start-Process -FilePath "wusa.exe" -ArgumentList "/quiet /norestart $($PatchFile.FullName)" -Wait

}

Replace the placeholders with the following information:


- `<KB_Number>`: The KB number of the specific Windows update you want to install.

- `<path_to_kb_file.msu>`: The path to the MSU file for the specific Windows update.

- `<Package_Name>`: The name of the package you want to install from Microsoft Update.

- `<Path_to_Patches_Folder>`: The path to the folder where the update files (MSU) are located.


The first example demonstrates how to install a specific Windows update using the `wusa.exe` command-line utility. You need to provide the KB number of the update and the path to the corresponding MSU file.


The second example shows how to install updates from Microsoft Update using the `Install-Package` cmdlet. Specify the name of the package you want to install and set the source to "MicrosoftUpdate".


The third example demonstrates how to install updates from a local folder. It retrieves all the MSU files in the specified folder using `Get-ChildItem` and then iterates over each file, using `wusa.exe` to install them silently.


Please note that administrative privileges are required to install updates, and the specific commands and parameters may vary depending on your operating system and the type of updates you are installing. Make sure to test and adapt the PowerShell commands based on your requirements and environment.

Post a Comment

Previous Post Next Post