好的,所以这一直困扰着我一段时间,现在我已经尝试了太多东西。
我想运行一个PowerShell脚本 - 我的用户帐户是一个常规的域名,但它是我的电脑上的本地管理员。因此,我创建了一个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主机中将参数传递给它。 –