2
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
}
stop-transcript

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.

john
  • 1,995
  • 2
  • 17
  • 30
Joel T
  • 59
  • 1
  • 2
  • 7
  • 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

3 Answers3

1

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!

john
  • 1,995
  • 2
  • 17
  • 30
  • 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
  • Thanks so much for sticking with this John. I found a way around it by not trying to capture output just get the installed on that date. The following code did this. get-hotfix|where {$_.InstalledOn -gt ((get-date).AddDays(-1))} The output just tells you what was installed on current date. – Joel T Jan 29 '15 at 16:36
0

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

Colyn1337
  • 2,397
  • 2
  • 23
  • 40
0

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
Hrvoje Špoljar
  • 5,245
  • 26
  • 42
Joel T
  • 59
  • 1
  • 2
  • 7