0
votes

I am trying to install pfx file automatically every time the Azure Pipeline runs, because with interactive process agent the files seems to loose the password or its just unable to import. Below is the powershell script i am trying to implement with not much success. I need to provide the password automatically:

Set-Location "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools"

Start-Process -FilePath "sn.exe" -ArgumentList "-NoExit","-d","$Container"

Start-Process -FilePath "sn.exe" -ArgumentList "-i $path $Container" -NoNewWindow -Wait

[System.Windows.Forms.SendKeys]::SendWait("$password") 

When the I run the script, i am getting below error:

Start-Process : This command cannot be run due to the error: The system cannot find the file specified. At C:\PowerShellScript\CertReInstall.ps1:12 char:1 + Start-Process -FilePath "sn.exe" -ArgumentList "-i $path $Container ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

I though of using "Import-PfxCertificate" but it does not seem to have option for providing the container name for the install.

Any help would be greatly appreciated. Thank you!

1
Judging by the error message, the system can't find the file specified in the $path variable. You should check if $path has a correct value.Theo
@theo Yes it has correct location and file. The user has full access to the same. If i remove "-NoNewWindow -Wait" it was fine.. Since i need it to automatically get the password i need to have those 2 parameters..suprasad

1 Answers

0
votes

After lot of trial and error finally i was able to figure out which path it was having issue. It was actually complaining about -FilePath "sn.exe" and not the path in the argument list. Even though the Set-Location did its job the second Start-Process was having issues. So i update the line as below:

Start-Process -FilePath "sn.exe" -ArgumentList "-i $path $Container" -NoNewWindow -Wait

This made the file not found error go away.