Passing Logging Arguments in PS Script

Hello,

I am using the following to attempt to install an update package for Adobe Acrobat Reader DC via Powershell script:

$UpdateDirectory = "C:\Temp"
$UpdatePath = (Get-ChildItem -Path $UpdateDirectory -Recurse | Where-Object {$_.Name -like "AcroRdrDCUpd*.msp"})
$file = ($UpdatePath).FullName
$arg1 = @(
    '/update'
    '$file'
    '/qn'
    '/L*V C:\test.log'
    )
Start-Process -Wait -FilePath msiexec.exe -ArgumentList $arg1 -PassThru

After running, I am prompted with the msiexec help window, no matter the changes I make to the code. This works fine, however, I was attempting to add the logging option:

$UpdateDirectory = "C:\Temp"
$UpdatePath = (Get-ChildItem -Path $UpdateDirectory -Recurse | Where-Object {$_.Name -like "AcroRdrDCUpd*.msp"})
$file = ($UpdatePath).FullName
$arg1 = "/update $file /qn"
Write-Host "Installing Adobe Acrobat Reader DC update version $TargetVersion"
Start-Process -Wait -FilePath msiexec.exe -ArgumentList $arg1 -PassThru

Can anyone help me figure out what I am doing wrong?

First thing is you need double quotes around $file. Single quotes mean string literals. Double quotes will allow the variable to expand

@krzydoug I really appreciate the quick response. I made the suggested change, but the result is still the same. Would you happen to have any other ideas?

$UpdateDirectory = "C:\Temp"
$UpdatePath = (Get-ChildItem -Path $UpdateDirectory -Recurse | Where-Object {$_.Name -like "AcroRdrDCUpd*.msp"})
$file = ($UpdatePath).FullName
$arg1 = @(
    '/update'
    "$file"
    '/qn'
    '/L*V C:\test.log'
    )
Start-Process -Wait -FilePath msiexec.exe -ArgumentList $arg1 -PassThru

Thanks again!

How many files do you get when you run your second line of code?

And BTW … this could be shortened like this:

$UpdatePath = Get-ChildItem -Path $UpdateDirectory -Filter 'AcroRdrDCUpd*.msp' -File -Recurse

@Olaf, I just get one file. I use wildcards so that I can just dump the latest update in the folder and run the script. Thanks for the tip on shortening the code!

Does the path have spaces in it?

You mentioned in your question that you have a working version. Why don’t you use this version?
If I got it right this should be enough:

$MSPFilePath = (Get-ChildItem -Path $UpdateDirectory -Filter 'AcroRdrDCUpd*.msp' -Recurse).FullName
$ArgumentList = "/update $MSPFilePath /qn /L*V C:\test.log"
Start-Process -FilePath msiexec.exe -ArgumentList $ArgumentList -PassThru -Wait

@Olaf that seems to work until I change $UpdateDirectory to $PSScriptRoot in the script. I put these scripts on a disc that is ran on multiple machines, and the drive letter for optical media varies from system to system.

So you have to start debugging your code. Start with outputting the variables youy use to the console and check if the output is what you expect it to be.

1 Like

Agreed. If you don’t already, I’d suggest a good debugger like the built-in one for VS Code. John Savll has a great video on how to use it.