I need to install CA certificate into LocaMachine Root via powershell. I'm trying to run this script with elevated privileges to Standard user from Administrators group.
Import-PfxCertificate -Password (ConvertTo-SecureString -String 'certificatePassword' -AsPlainText -Force) -CertStoreLocation Cert:\LocalMachine\Root -FilePath 'filePath'
But, it fails on Acces Denied error.
If I execute the same script with elevated privileges to predefined windows Administrator user, then it works without error.
How to configure Standard user permissions to allow access?
I need to install it remotely via API and I don't want to require the predefined windows Administrator credentials from app using this API.
Thx in advance.
UPDATE (here is the screenshot of Standard user from Administrators group and the C# code where the process is started with credentials of this user):
command = the powershell script above
adminUsername = 'Admin'
adminPasswprd = '*****'
domain = 'computername'
public static (bool, string) ExecuteCommand(string command, string adminUsername, string adminPassword, string domain = "")
{
try
{
SecureString securePassword = new SecureString();
foreach (char c in adminPassword)
{
securePassword.AppendChar(c);
}
// Create PowerShell process information
ProcessStartInfo processInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-NoProfile -ExecutionPolicy Bypass -Command \"{command}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = false,
CreateNoWindow = true,
UserName = adminUsername,
Password = securePassword,
Domain = domain,
Verb = "runas"
};
using (Process process = new Process())
{
process.StartInfo = processInfo;
process.Start();
string standardOutput = process.StandardOutput.ReadToEnd();
string errorOutput = process.StandardError.ReadToEnd();
process.WaitForExit();
if (!string.IsNullOrEmpty(errorOutput))
{
standardOutput += Environment.NewLine + "Error: " + errorOutput;
}
return (string.IsNullOrEmpty(errorOutput), standardOutput);
}
}
catch (Exception ex)
{
return (false, $"Error during PowerShell script execution: {ex.Message}");
}
}