I created an Powershell Script to execute an MSI Installer from Packer AMI Build has ended up following error,
C:\Users\Administrator\Downloads\managesoft\FlexNetInventoryAgent.msi
This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.
Below is my PowerShell script,
Invoke-WebRequest -Uri https://jfrog/artifactory/generic-flexera-flexera-one-virtual/PROD/Windows%20-%20Silent%20Install/managesoft.zip -OutFile "C:\Users\Administrator\Downloads\managesoft.zip" -Headers @{ "X-JFrog-Art-Api" = "$artifactory_key"}
Expand-Archive -Path C:\Users\Administrator\Downloads\managesoft.zip -DestinationPath C:\Users\Administrator\Downloads\managesoft
Get-ChildItem "C:\Users\Administrator\Downloads\managesoft" -recurse | where {$_.extension -eq ".msi"} | Rename-Item -NewName { $_.Name -replace ' ','' }
$msi_install_path = Get-ChildItem "C:\Users\Administrator\Downloads\managesoft" -recurse | where {$_.extension -eq ".msi"} | % {Write-Host $_.FullName}
msiexec.exe /i "$msi_install_path" /qn
$msi_install_path value is null in your case as full path of msi is being written to host but not being assigned to variable. Following should work:
$msi_install_path = Get-ChildItem "C:\Users\Administrator\Downloads\managesoft" -recurse | where {$_.extension -eq ".msi"} | % { $_.FullName }