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
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
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.```
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.