0

Trying to create a Powershell script that installs an application (.exe) with stored credentials (Clixml).

Everything works fine when using:

Start-Process -FilePath "C:\Users\$($env:USERNAME)\Downloads\Software\Software.exe" -ArgumentList '/s' -Credential $credentials

But I would like a more elegant solution:

$startprocessParams = @{
    FilePath     = "C:\Users\$($env:USERNAME)\Downloads\Software\Software.exe"
    ArgumentList = '/s'
    Credential   = $credentials
    Verb         = 'RunAs'
    PassThru     = $true
    Wait         = $true
}
$proc = Start-Process @startprocessParams

if ($proc.ExitCode -eq 0) {
    'Software installed!'
}
else {
    "Fail! Exit code: $($Proc.ExitCode)"
}

This works perfectly without the Credential parameter, you then get the "enter credentials/UAC" popup that I would like to avoid. With the Credential parameter I get this error:

Start-Process : Parameter set cannot be resolved using the specified name parameters.

What am I missing here? Appreciate any advice and/or guidance.

EDIT:

I use the following line to import the credentials:

$credentials = Import-Clixml "C:\Users\$Env:USERNAME\AppData\Local\Apps\SOFTWARE\cred.xml"

The credentials is created with a standard:

Get-Credential | Export-Clixml "C:\Users\$Env:USERNAME\AppData\Local\Apps\SOFTWARE\cred.xml"

This works as it should.

TheFM
  • 3
  • 3

2 Answers2

0

you need to set the credentials as PSCredential. have a look at this solution:

$username = "username"

$password = "password"


$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))


Start-Process dnscrypt-proxy.exe -WorkingDirectory path_here -Credential ($credentials)

is it stored in PSCredential in the first place?

Koko Jumbo
  • 313
  • 1
  • 5
0
Start-Process : Parameter set cannot be resolved using the specified name parameters.

The error tells us the set of parameters used is incorrect. Checking the MSDN doc or Get-Help for Start-Process will show that -Credential can not be used with -Verb.