好的,这个问题困扰了我一段时间,我已经尝试了太多方法。
我正在尝试运行一个PowerShell脚本 - 我的用户帐户在域上是普通用户,但是在我的计算机上它是本地管理员。因此,我创建了一个提示我输入凭据(在其中我键入我的域管理员帐户的凭据)的PowerShell脚本,用于调用需要该域管理员权限的另一个脚本。
这个脚本看起来像这样:
Invoke-Command -FilePath "C:\Temp\script.ps1" -ComputerName localhost -Credential Get-Credential
这里的script.ps1
是需要域管理员权限的脚本。
执行显示的脚本会提示输入凭据,然后出现以下错误:
[localhost] Connecting to remote server localhost failed with the following error message : Access is denied.
我试着玩弄一个看起来像这样的 .bat 文件:
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%script.ps1 PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";
我也尝试过,但无法使其正常工作 - 它无法将脚本提升到域管理员级别。
最后,我需要提到的是,如果我使用域管理员权限打开PowerShell,导航到C:\ Temp \ script.ps1并通过.\ script.ps1执行它,我想要使用域提升运行的脚本可以正常工作。
有什么建议吗?