无法在Windows Server 2016无人参与安装中执行远程poweshell脚本

我正在尝试为Windows Server 2016无人参与安装创buildunattended.xml文件,在安装Windows之后,它应该执行位于远程samba共享上的一个powershell脚本。

我正在使用以下命令来运行存储在samba共享中的powershell脚本:

cmd.exe /c "ECHO R | powershell.exe -ExecutionPolicy Unrestricted -File \\192.168.137.131\install\ConfigureRemotingForAnsible.ps1" 

无人参与安装过程工作正常,但ConfigureRemotingForAnsible.ps1脚本执行失败,错误:

 The argument '\\192.168.137.131\install\ConfigureRemotingForAnsible.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter. 

当我手动运行它时,相同的命令执行成功。

unattended.xml文件的相关部分:

 <settings pass="specialize"> <component name="Microsoft-Windows-Deployment" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <RunSynchronous> <RunSynchronousCommand wcm:action="add"> <Credentials> <Username>Administrator</Username> <Password>Devops@123</Password> </Credentials> <Path>cmd.exe /c "ECHO R | powershell.exe -ExecutionPolicy Unrestricted -File \\192.168.137.131\install\ConfigureRemotingForAnsible.ps1 > c:\pss.txt"</Path> <Order>1</Order> <Description>Execute ansible script</Description> </RunSynchronousCommand> </RunSynchronous> </component> </settings> 

有人可以告诉我什么我应该添加在我的unattended.xml使其工作?

提前致谢。

从文档看来,Path项目是使用提供的凭据访问的,但不能 。 广义上说, Specialize期间的RunSynchronousCommand运行在系统上下文中,而AuditUser将作为用户运行。

一些选项:

  • Specialize期间,使用net useNew-PSDrive将具有显式凭证的驱动器映射到远程共享
  • 把你的命令放在AuditUser 。 在OP的评论中,提到这有其他问题。
  • 创build一个pipe理员AutoLogon,并在SetupComplete.cmd中运行您的命令

我指的是https://docs.microsoft.com/en-us/windows-hardware/customize/desktop/unattend/microsoft-windows-deployment-runsynchronous-runsynchronouscommand-credentials和https&#xFF1A:// technet上的文档.microsoft.com / EN-US /库/ cc722343(v = ws.10)的.aspx