2016-10-03 40 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