Start-Process as Admin

Hello All,

I’m trying to write a small script that installs an MSI (not anything spectacular) but I’m running into an error when using the Start-Process cmdlet with the -Credential switch. I was wondering if you all had any insight…

…output truncated…

$AESkey = “location of key”

$EncryptedPassword = “long string of garbage”

$Key = Get-Content $AESkey

$SecuredCreds = ConvertTo-SecureString $EncryptedPassword -Key $Key

$ScriptAdminCreds = New-Object System.Management.Automation.PSCredential (“domain\scriptadmin”, $SecuredCreds)

$Arguments = “/package C:\Users\testuser\Desktop\anyconnect-win-4.5.05030-core-vpn-predeploy-k9.msi /norestart /passive”

Start-Process “C:\Windows\System32\msiexec.exe” $Arguments -Credential $ScriptAdminCreds

…END…

This is the error – Start-Process : This command cannot be run due to the error: The directory name is invalid.

 

Everything works great, except the last line. I am able to run the start-process without the -Credential switch and it works great. But this thing is gonna be run @ logon under user creds and MSIexec needs elevated permissions.

I’ve verified that “domain\scriptadmin” does have NTFS access to System32. I’ve also researched this and tried being more specific with the -filepath switch but I get the same result .(https://www.reddit.com/r/PowerShell/comments/5h7jbr/startprocess_error_directory_name_is_invalid_but/)

Thanks for taking the time to read this. I always appreciate any and all feedback.

Have a great day! -Jared

 

 

Does the script admin user has access to testuser user’s desktop folder ?
Can you try keeping this MSI in c:\temp folder and try .

Thanks for your response – that user does have access to the testuser desktop. I also tried moving the MSI into C:\temp and the results were the same.

I get the same error running this (no args): Start-Process “C:\Windows\System32\msiexec.exe” -Credential $ScriptAdminCreds

I ran into this issue myself trying to automate software deployments. A suggestion to your $argument variable, prepend your existing string with the /C switch see below:

$Arguments = "/C /package C:\Users\testuser\Desktop\anyconnect-win-4.5.05030-core-vpn-predeploy-k9.msi /norestart /passive"

You have to specify /C before passing cmd any arguments from Powershell start-process cmdlet. I hope this information is helpful for you.