简体   繁体   English

安装Microsoft 2010的Powershell脚本

[英]Powershell Script to Install Microsoft 2010

I am trying to copy a file from the server to a pc to automatically install Microsoft Office 2010. I am getting the following error when just trying to use the CopyItem portion. 我试图将文件从服务器复制到PC以自动安装Microsoft Office2010。当我尝试使用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

(Well I just figured out the above error is because the computer name and user name are different so that took care of that error, but the script is still not working because I am not sure how this line should read $InstallString = '"C:\\windows\\temp\\Office 2010\\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml"' ) (我只是想出了上述错误,是因为计算机名和用户名不同,因此可以解决该错误,但是脚本仍然无法正常工作,因为我不确定此行应如何读取$InstallString = '"C:\\windows\\temp\\Office 2010\\setup.exe" /adminfile Updates/OfficeSetup.MSP /config ProPlus.WW/config.xml"'

This is my code so far to copy Office 2010 to the pc to automatically run the install. 到目前为止,这是我的代码,可以将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
}
}

Once the file is transferred to the computer I was thinking the I could do something like this 将文件传输到计算机后,我开始考虑可以做这样的事情

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

看起来您在config.xml之后只是多了一个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM