Start-Transcript c:\scripts\InstallUpdates.log -Append # -NoClobber
$SourceMSUFiles = (get-content install-list.txt | where {$_ -like "*.msu"})

#Install MSU files

foreach($file in $SourceMSUFiles)
    $Argument= "$Files",' /quiet',' /norestart'
    & start wusa -ArgumentList @Argument -Wait # -RedirectStandardOutput "c:\scripts\InstallUpdates.log"
    Write-Host "Installing $file" `n

In normal cmd line this would work like this:

wusa $files /quiet /norestart

I want to use Powershell to do what I would normally do with command line.

  • Also, it looks like you're using $Files as the argument, when the variable inside the foreach loop would be $file. – jbsmith Jan 29 '15 at 20:45

You can just use the same command actually. Or were you after something more idiomatic? I think it's easier to start executables using the CMD syntax, unless you see some strange errors (K.I.S.S.). Even redirection works:

Get-Content install-list.txt | Where-Object {$_ -like "*.msu} | Foreach-Object {
    wusa $_ /quiet /norestart >> "c:\script\installupdates.log" | Wait-Process

When I tried this against bogus updates, the log file was empty. I think this might be to do with the quiet option. It seems quiet in the command line too!

  • I am trying to do 2 things besides install the windows patches. 1. get a log file of actions result. 2. Make sure each file gets to finish the install before going to the next. I tested Johns' solution and it installed correctly but I go no log. BTW the quiet is just so you don't get asked the confirm question it doesn't affect output. – Joel T Jan 28 '15 at 12:03
  • @joelt I updated the code. 1. I had used > instead of >> as the redirection operator. >> will append rather than overwrite. 2. Added pipe to Wait-Process to install updates sequentially. Do you see any output to the log file now? – john Jan 28 '15 at 18:47
  • @joelt also, bear in mind that you're logging output to the same file as the transcript so any output to the console should be included in the transcript without having to redirect it. – john Jan 28 '15 at 18:49
  • Thanks, John now it runs updates one at a time and completes all successfully. I just get an empty log for some reason. – Joel T Jan 29 '15 at 13:28
  • @JoelT what does the output normally look like if you just run an single update, no script? – john Jan 29 '15 at 15:36

In powershell you call it just as you would in CMD. No need to use Start-Process.


Johns' answer solved the problem.

Final Code

Get-Content install-list.txt | Where-Object {$_ -like "*.msu"} | Foreach-Object {
    wusa $_ /quiet /norestart >> "c:\script\installupdates.log" | Wait-Process
Write-Host "Installed patches on"
((get-date -DisplayHint Date))
get-hotfix|where {$_.InstalledOn -gt ((get-Date).AddDays(-1))}|Select HotfixId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.