![](/img/trans.png)
[英]How do I call an elevated PowerShell from Windows command prompt to execute commands and a PowerShell script file?
[英]How do i Run powershell with elevated credential in the script then execute files in their locations
我想在单击 .ps1 时执行 3 个不同的文件。 我希望它已经拥有提升的凭据
$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'
我不知道它是否在做什么
尝试对您的 bat 文件使用Start-Process
而不是Get-Item
:
Start-Process c:\path\to\file.bat
您还可以使用此问题的答案来使用您的 reg 文件:
reg import .\path\to\reg.reg
您可以使用-Credentials
参数传递您的凭据。 它将模拟用户运行命令。
因此,在您的 .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.