0
votes

I have created a password file for the account with Administration privileges with the following script:

$passwd = Read-Host "Enter password" -AsSecureString
$encpwd = ConvertFrom-SecureString $passwd
$encpwd > "C:\Users\b_steya\Documents\password_b_steya.bin"

Then, in another powershell script I try to run an elevated PowerShell cmd

$encpwd = Get-Content "C:\Users\b_steya\Documents\password_b_steya.bin"
$passwd = ConvertTo-SecureString $encpwd
$cred = new-object System.Management.Automation.PSCredential 'main\b_steya',$passwd

Start-Process PowerShell -Cred $cred -ArgumentList '-noexit','-File','C:\Users\b_steya\Documents\TestAddIISAppPool.ps1'

When executing the second script, I get the following error message: Import-Module : Process should have elevated status to access IIS configuration data.

What am I doing wrong? The user "main\b_steya" is added to the local Administrators group of the machine, on wich the script is executed.

Best regards Yannik

1

1 Answers

0
votes

When your second script is executed is it done so from an administrator (runas administrator) powershell session? Even though the user is part of the local admin group you still often need to have the initial process elevated.