[英]How do i Run powershell with elevated credential in the script then execute files in their locations
I want to execute 3 different files when I click on the .ps1.我想在单击 .ps1 时执行 3 个不同的文件。 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我不知道它是否在做什么
You can pass your credentials with the -Credentials
parameter.您可以使用
-Credentials
参数传递您的凭据。 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.因此,在您的 .ps1 脚本中,您可以在您调用的 PS Cmdlet 中添加
-Credentials $credential
。
-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.```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.