远程安装WMF5.1遇到的坑

最近需要通过远程PowerShell命令,在另外一台Window Server 2008R2的机器上安装WMF5.1,结果安装失败。提示我Denied Access。 百思不得其解,我明明用的账号是admin权限的,为什么不行呢?
安装的命令如下:

 "C:\setup\ext\PkgInstallOrder.txt" | ?{$_ -like "*.cab"} | %{$_.Split("=")[1]} | `
  ForEach-Object {
   $cmd ="winrs.exe -r:localhost  dism.exe /online /add-package /PackagePath:'C:\setup\ext\$_'"
   $cmd | out-File "C:\setup\15.txt" -append
   Invoke-Expression $cmd -ErrorAction stop | Out-File "C:\setup\15.txt" -Append
   } -ErrorVariable d
   $d | Out-File "C:\setup\15.txt" -Append

后面分析了半天,原来运行winrs竟然可以直接在后面加 -u 和-p的参数,从而指定某一个具体的用户来运行。

gc "C:\setup\ext\PkgInstallOrder.txt" | ?{$_ -like "*.cab"} | %{$_.Split("=")[1]} | `
  ForEach-Object {
   $cmd ="winrs.exe -r:localhost -u:'example.com\myadminaccount' -p:'password.' dism.exe /online /add-package /PackagePath:'C:\setup\ext\$_'"
   $cmd | out-File "C:\setup\15.txt" -append
   Invoke-Expression $cmd -ErrorAction stop | Out-File "C:\setup\15.txt" -Append
   } -ErrorVariable d
   $d | Out-File "C:\setup\15.txt" -Append

问题终于解决了,可以回家了。

你可能感兴趣的:(PowerShell,winrm,winrs)