我試圖使用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
是的,我有電腦的管理員權限 –
有沒有一個命令,我可以輸入,看看我的權利呢? –