Powershell - Installing software while passing Admin Credentials
First off, I want to say that I have learned a lot from ITNinja. I started packaging 2 months ago and have come a long way. I do not have much if any experience with PowerShell. I have a couple of years of coding experience with C# so I am starting to understand what I am looking at.
I am currently trying to install an MSI that requires a computer Administrator installation. The System account only has Admin Privileges so will not complete the installation.
I have found some workarounds that I am thinking that will work. I have a PowerShell script that will create an Administrator account on the computer. My intention was to use PSEXEC to install the MSI application by adding the Username and Password into the PSEXEC command; however, the machine that is executing the code is logged in as a standard user and the Code is executing through an account with admin privileges but not elevated. UAC is blocking PSEXEC from running elevated.
As stated, I am learning a few things, I know that using the following command, I can create a text file that can be used to encrypt the password:
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt`
From there, I found the following code which helps setup the credentials for use:
$username = "domain01\admin01" $password = cat C:\securestring.txt | convertto-securestring $cred = new-object -typename System.Management.Automation.PSCredential ` -argumentlist $username, $password
Since, this will be done on a Local Computer, using a local administrator account, I want the $username to use $env:computername\<ADMINACCT>
The part that I am struggling with and hope that someone can assist with is how I take the data captured above into executing the installation of the application using the local admin account.