1

I want to execute 3 different files when I click on the .ps1. I want it to already have the elevated credentials within

$credential = New-Object System.Management.Automation.PsCredential(".administrator", (ConvertTo-SecureString "P@ssw0rd" -AsPlainText -Force))

Start-Process CMD.exe -Verb runAs -PassThru 

Get-Item -FilePath '\\I:\Mo Khalifa\eBillingHub\utils\addper.bat'

Get-Item -FilePath '\\I:\Mo Khalifa\eBillingHub\utils\AddToTrustedSites.reg' 

Get-Item -FilePath '\\I:\Mo Khalifa\eBillingHub\utils\DotNetPermissions.reg'

I don't know if its doing anything

techguy1029
  • 743
  • 10
  • 29
Khalifa96
  • 47
  • 2
  • 10

2 Answers2

1

Try using Start-Process instead of Get-Item for your bat file:

Start-Process c:\path\to\file.bat

You can also use the answer from this question to use your reg files:

reg import .\path\to\reg.reg
I.T Delinquent
  • 2,305
  • 2
  • 16
  • 33
0

You can pass your credentials with the -Credentials parameter. It will impersonate the user to run the commands.

So in your .ps1 script, you could add the -Credentials $credential in the PS Cmdlets that you're calling.

-Credential <PSCredential>
        Specifies a user account that has permission to perform this action. Type a user name, such as User01 or
        Domain01\User01, or enter a PSCredential object, such as one from the Get-Credential cmdlet. By default, the
        cmdlet uses the credentials of the current user.```
Peter Kay
  • 926
  • 1
  • 7
  • 18