我试图使用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 :
有谁愿意帮我想出解决办法,我一直挣扎在这天!?
你的第一个错误可能意味着你没有权利来启动该服务,你有没有在该计算机上管理员权限? 对于Win32_Process.Create(),您要运行的最大问题是setup.exe需要交互式会话。 [此前一篇文章](http://serverfault.com/questions/690852/use-powershell-to-start-a-gui-program-on-a-remote-machine)在这个问题上给出了一个很好的解决方案。 – BenH
是的,我有电脑的管理员权限 –
有没有一个命令,我可以输入,看看我的权利呢? –