2016-10-03 80 views
0

我試圖使用PowerShell安裝Microsoft Office。不幸的是,我遇到了兩個我無法弄清楚如何解決的錯誤。有人請引導我進入正確的方向嗎?PowerShell中安裝Office腳本未知錯誤和RemoteRegistry cannont打開

腳本

Function Get-FileName{ 
[CmdletBinding()] 
Param(
    [String]$Filter = "|*.*", 
    [String]$InitialDirectory = "C:\") 

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") 
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog 
    $OpenFileDialog.initialDirectory = $InitialDirectory 
    $OpenFileDialog.filter = $Filter 
    [void]$OpenFileDialog.ShowDialog() 
    $OpenFileDialog.filename 
} 

$file = Get-FileName -InitialDirectory $env:USERPROFILE\Desktop -Filter "Text files (*.txt)|*.txt|All files (*.*)|*.*" 
ForEach ($item in (Get-Content $file)) { 
    $sitem = $item.Split("|") 
    $computer = $sitem[0].Trim() 
    $user = $sitem[1].Trim() 

    $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\Install\Office2010" -Destination "\\$computer\c$\windows\temp\" -Container -Recurse -Force 

    $InstallString = '"C:\windows\temp\Office2010\setup.exe"' 
    ([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create($InstallString) 

    "$computer" + "-" + "$(Get-Date)" | Out-File -FilePath "\\server\Install\Office2010\RemoteInstallfile.txt" -Append 

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

錯誤

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



__GENUS   : 2 
__CLASS   : __PARAMETERS 
__SUPERCLASS  : 
__DYNASTY  : __PARAMETERS 
__RELPATH  : 
__PROPERTY_COUNT : 2 
__DERIVATION  : {} 
__SERVER   : 
__NAMESPACE  : 
__PATH   : 
ProcessId  : 
ReturnValue  : 8 
PSComputerName : 

有誰願意幫我想出解決辦法,我一直掙扎在這天!?

+0

你的第一個錯誤可能意味着你沒有權利來啓動該服務,你有沒有在該計算機上管理員權限? 對於Win32_Process.Create(),您要運行的最大問題是setup.exe需要交互式會話。 [此前一篇文章](http://serverfault.com/questions/690852/use-powershell-to-start-a-gui-program-on-a-remote-machine)在這個問題上給出了一個很好的解決方案。 – BenH

+0

是的,我有電腦的管理員權限 –

+0

有沒有一個命令,我可以輸入,看看我的權利呢? –

回答

1

首先要確保當你打開PowerShell中(或運行PS1文件。無論您的應用程序而定),右鍵單擊它,然後單擊以管理員身份運行。

至於你的安裝腳本,你嘗試運行它作爲一種服務?你不會有,如果你做這種方式啓用遠程註冊表服務:

Copy-item "\\servershare\Office 2010" -conatiner -recurse \\computer\c$\windows\temp\ 
Invoke-Command -Computername computer -ScriptBlock { 
    Start-process "C:\windows\temp\office 2010\setup.exe"} 

這裏是參照該script。 看看是否給你不同的結果。如果沒有,那麼你的管理權限就有問題了。您運行腳本的帳戶不是目標計算機上本地管理員組的成員,也不是您運行它的計算機上的本地管理員。

這也是明智的,有一個.msp文件來配置,如果你想安裝到無需任何用戶交互的靜默運行從腳本安裝Office。如果你還沒有創建一個msp文件,微軟的網站會通過一步一步的指導來解釋它。

+0

以管理員身份運行右擊使工作 –

+0

也-conatiner拼寫錯誤或者是這也是一個命令IV見過它多次完全相同的方式,我永遠都只是以爲是拼寫錯誤 –

+0

抱歉這麼晚纔回復。它是 - 容器。我的不好。 – takeitback