我想通过 powershell 运行一些命令来远程执行 Sysprep。
所以首先我使用这个创建了一个会话:
$UserName = "IPAddress\username"
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
$s = New-PSSession -ComputerName IPAddress -Credential $psCred
然后分配 Sysprep 中使用的变量:
$sysprep = 'C:\Windows\System32\Sysprep\Sysprep.exe'
$arg = '/generalize /oobe /shutdown /quiet'
$sysprep += " $arg"
然后最后运行这个:
Invoke-Command -Session $s -ScriptBlock {$sysprep}
当我运行最后一个命令时,实际上什么都没有发生。但是在脚本块中$sysprep
,如果我给出任何其他命令,例如启动/停止服务,它会给出一些响应。但是 SysPrep 命令似乎不起作用。任何人都可以建议我做错了什么。