繁体   English   中英

如何以管理员身份从批处理文件运行 powershell 脚本以加入域?

[英]How can i run a powershell script from a batch file as admin to join a domain?

我正在尝试以管理员身份运行从 a.cmd 运行它

powershell -Command "&{ Start-Process powershell Add-Computer -Domain "domain.domain" -Credential login -Verb RunAs -Wait -Confirm}"

输入密码的 window 确实弹出,但在我输入密码后,我的批处理脚本出现以下错误。

Start-Process : O conjunto de parâmetros não pode ser resolvido usando os parâmetros nomeados especificados.
No linha:1 caractere:4
+ &{ Start-Process powershell Add-Computer -Domain domain.domain -Cr ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand

我想通过脚本加入域,我尝试使用 .netdom,但它是服务器独有的。 我正在处理 Windows 10 的客户端笔记本,离服务器很远,而且我对服务器域没有任何管理员访问权限。 我只是将大量计算机格式化为指定的 state,这包括加入域。 我不在乎我是如何加入域的,只要我自动加入域(如果不可能,要求输入密码是可以接受的),从批处理或 powershell 脚本,并且不安装任何东西。

在 a.cmd 文件中使用以下内容怎么样:

powershell -executionpolicy bypass -noexit "& ""C:\your\path\to\domainjoinscript.ps1"""

如何运行 PowerShell 脚本

-executionpolicy bypass标志是因为默认情况下,PowerShell 不允许您运行不受信任的脚本(即使您创建了它们)。 您必须在系统范围内禁用执行策略,或者这样做。

您的.ps1文件应包含:

add-computer -domainname "yourdomain" -restart

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM