2016-09-29 114 views
0

我想从服务器复制文件到PC来自动安装Microsoft Office 2010.我刚刚尝试使用CopyItem部分时出现以下错误。Powershell脚本安装微软2010

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 

(好吧,我只是想出了上面的错误是由于计算机名和用户名是不同的,这样把这个错误的照顾,但脚本仍然没有工作,因为我不知道这条线应该如何请阅读$InstallString = '"C:\windows\temp\Office 2010\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml"'

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

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 
} 
} 

一旦文件被传输到电脑我在想我可以做这样的事情

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 
    $InstallString = '"C:\windows\temp\Office 2010\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml"' 
    ([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create($InstallString) 

    "$computer" + "-" + "(Get-Date)" | Out-File -FilePath "\\server\Orig\Install\RemoteInstallfile.txt" -Append 
    } 
    Else 
    { 
    "$computer" + "_Already_Had_Software_" + "(Get-Date)" | Out-File -FilePath "\\server\Orig\Install\RemoteInstallfile.txt" -Append 
    } 
} 

回答

0

看起来你只是有一个额外的“config.xml文件后

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