- 1 year ago
Network install hotfixes with Powershell
To install hotfixes on remote computers over a network using PowerShell, you can utilize the PowerShell Remoting feature and the Invoke-Command
cmdlet. Here's an example of how you can achieve this:
Create a text file: Create a text file, such as
computers.txt
, and list the names or IP addresses of the remote computers, each on a new line.Open PowerShell with administrative privileges: Open PowerShell with administrative privileges on your local computer.
Import the hotfix list: Import the list of hotfixes you want to install. You can create an array variable with the KB numbers of the hotfixes you wish to install. For example:
powershell$hotfixes = @("KB123456", "KB789012", "KB345678")
Use Invoke-Command: Use the
Invoke-Command
cmdlet to run commands on the remote computers listed in thecomputers.txt
file. Specify the-FilePath
parameter to run a script file on the remote computers. Here's an example script:powershell$computers = Get-Content -Path "computers.txt"
$session = New-PSSession -ComputerName $computers
Invoke-Command -Session $session -FilePath "install_hotfix.ps1" -ArgumentList $hotfixes
Remove-PSSession -Session $session
In the example above,
install_hotfix.ps1
is the name of the script file that will be executed on the remote computers. The-ArgumentList
parameter is used to pass the$hotfixes
array to the script.Create the install_hotfix.ps1 script: Create the
install_hotfix.ps1
script file that will be executed on the remote computers. Inside the script file, you can use thewusa.exe
command to install the hotfixes. Here's an example of the script:powershellparam(
[string[]]$hotfixes
)
foreach ($hotfix in $hotfixes) {
$command = "wusa.exe $hotfix /quiet /norestart"
Invoke-Expression -Command $command
}
The
param
block defines the input parameter, and the script uses a loop to iterate through the hotfixes and installs them using thewusa.exe
command.Run the PowerShell script: Save the PowerShell script file, and then run the main PowerShell script you created in step 4. The script will install the specified hotfixes on the remote computers listed in
computers.txt
.
Ensure that you have the necessary permissions and network connectivity to the remote computers. Also, make sure that the hotfixes you are installing are applicable to the operating systems and versions running on the remote computers.
Note: Running scripts and executing commands remotely using PowerShell Remoting requires appropriate permissions and configuration. Consult the PowerShell documentation for more information on setting up PowerShell Remoting and executing commands on remote computers.