【发布时间】:2016-07-26 23:47:40
【问题描述】:
好的,所以这一直困扰着我一段时间,我现在尝试了太多东西。
我正在尝试运行 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 执行它,我想用域提升运行的脚本是有效的。
有什么建议吗?
【问题讨论】:
-
如果您只是想在本地机器上执行脚本,为什么要使用invoke-command?您可以在您的 powershell 主机中运行脚本并将参数传递给它。
标签: windows powershell localhost invoke-command