0

I am getting the following errors with a script that auto installs all updates in the current directory:

At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:15 char:25
+         $command = "Expand –F:* '" + $msu.fullname + "' '" + $PSScr ...
+                               ~~~
Unexpected token 'F:*' in expression or statement.
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:29 char:82
+ ... = "Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase"
+                                                                         ~
The string is missing the terminator: ".
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:13 char:5
+     {
+     ~
Missing closing '}' in statement block or type definition.
At K:\Operating System\ConfigureWindows10\Updates\Install-Updates.ps1:10 char:1
+ {
+ ~
Missing closing '}' in statement block or type definition.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

Here is the code body:

{
$msu = get-childitem -path $PSScriptRoot -Recurse | where ($_.extension -eq ".msu") | select fullname
foreach($package in $msu)
{
    write-debug $msu.fullname
    $command = "Expand –F:* '" + $msu.fullname + "' '" + $PSScriptRoot + "'"
    write-debug $command
    Invoke-Expression $command
}

$updates = get-childitem -path $PSScriptRoot -Recurse | where ($_.extension -eq ".cab") | select fullname
foreach($update in $updates)
{
    write-debug $update.fullname
    $command = "dism /online /add-package /packagepath:'" + $update.fullname + "'"
    write-debug $command
    Invoke-Expression $command
}

$command = "Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase"
Invoke-Expression $command
}
5
  • When saving script file as UTF-8 use UTF-8 with BOM. Commented Apr 22, 2017 at 5:28
  • Thanks. The script works however I am getting another error. The script doesn't expand any msu file in directory. Commented Apr 22, 2017 at 5:39
  • Update in code : Commented Apr 22, 2017 at 5:40
  • $msu = get-childitem -path $PSScriptRoot -Recurse | where ($_.extension -eq ".msu") | select fullname foreach($package in $msu) { write-debug $package.fullname $command = "Expand –F:* '" + $package.fullname + "' '" + $PSScriptRoot + "'" write-debug $command Invoke-Expression $command } Commented Apr 22, 2017 at 5:40
  • Is this a - (minus) or a dash before the F? Commented Apr 23, 2017 at 17:31

2 Answers 2

1

After "where" you need a script block which usually is in curly brackets, not in simple ones.

 ...| where {$_.extension -eq ".msu"} |...
Sign up to request clarification or add additional context in comments.

2 Comments

Changing () to {} did work however the script just executes Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase. Nothing else is executed.
In the loop: foreach($package in $msu) {...} you use the $msu.fullname which is not good, you should use the $package.fullname instead.
0
  • You use the var $msu instead of $package in the first foreach.
  • Aside from the curly brackets in the where clause, you could omit it specifying a -Filter *.msu parameter in the Get-ChildItem.
  • IMO the select isn't necessary
  • the quoting doesn't seem right, use a here string instead

Try this (untested)

{
    $msu = get-childitem -path $PSScriptRoot -Recurse -Filter *.msu
    foreach($package in $msu){
        write-debug $package.FullName
$command = @'
& Expand.exe –F:* "$package.FullName" "$PSScriptRoot"
'@
        write-debug $command
        Invoke-Expression $command
    }
    $updates = get-childitem -path $PSScriptRoot -Recurse -Filer *.cab
    foreach($update in $updates){
        write-debug $update.fullname
$command = @'
& Dism.exe /online /add-package /packagepath:"$update.FullFame"
'@
        write-debug $command
        Invoke-Expression $command
    }
    $command = "Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase"
    Invoke-Expression $command
}

3 Comments

At K:\OperatingSystem\ConfigureWindows10\Updates\Extract-Updates.ps1:8 char:5 + '@ + ~~ White space is not allowed before the string terminator. At K:\OperatingSystem\ConfigureWindows10\Updates\Extract-Updates.ps1:4 char:1 + { + ~ Missing closing '}' in statement block or type definition. At K:\OperatingSystem\ConfigureWindows10\Updates\Extract-Updates.ps1:1 char:1 + { + ~ Missing closing '}' in statement block or type definition. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : WhitespaceBeforeHereStringFooter
Changed the script above removing the indents with the here strings.
The 2nd and 3rd error refer to a mismatch in closing curly brackets which doesn't stem from my code, please revise the text carefully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.