用于安装Microsoft 2010的Powershell脚本

时间:2016-09-29 20:55:27

标签: powershell

我正在尝试将文件从服务器复制到PC以自动安装Microsoft Office 2010.我在尝试使用CopyItem部分时收到以下错误。

Start-Service : Service 'Remote Registry (remoteregistry)' cannot be started due to the following error: Cannot open remoteregistry service on computer 'IT-PCName'.
At line:21 char:54
+ Get-Service remoteregistry -ComputerName $computer | Start-Service
+                                                      ~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

(我刚刚弄清楚上面的错误是因为计算机名称和用户名不同以便处理该错误,但脚本仍然无法正常工作,因为我不确定这行应该如何读取{{1 }})

这是我的代码到目前为止将Office 2010复制到PC以自动运行安装。

$InstallString = '"C:\windows\temp\Office 2010\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml"'

将文件传输到计算机后,我想我可以做这样的事情

 ForEach ($computer in (GC (Get-FileName -InitialDirectory $env:USERPROFILE\Desktop -Filter "Text files (*.txt)|*.txt|All files (*.*)|*.*"))) {

    $filepath = Test-Path -Path "\\$computer\C:\Program Files (x86)\Microsoft Office"
         If ($filepath -eq $false)
         {
    Get-Service remoteregistry -ComputerName $computer | Start-Service
         Copy-Item -Path "\\server\Orig\Install\Office2010" -Destination "\\$computer\c$\windows\temp\" -Container -Recurse -Force
}
}

1 个答案:

答案 0 :(得分:0)

看起来你只需要一个额外的“在config.xml之后

$InstallString = '"C:\windows\temp\Office 2010\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml'