无法在PowerShell中执行命令

时间:2017-09-18 10:30:47

标签: powershell ms-office

尝试执行以下操作:

function Repair-Office-Apps {
    $OfficeRepair = "/repair ProPlus /config \\server\path$\Custom\MS_Repair\SilentRepairConfig.xml"
    $Office2013   = "\\server\packagepath$\MsOffice2013\setup.exe"
    $Office2016   = "\\server\packagepath$\MsOffice2016\setup.exe"

    # Detect Office Version and repair
    $applist = Get-WmiObject -Class Win32_Product | Where-Object {
        $_.Name -like "*Microsoft Office Professional Plus 2010*" -or
        $_.Name -like "*Microsoft Office Professional Plus 2013*" -or
        $_.Name -like "*Microsoft Office Professional Plus 2016*"
    }

    if ($applist) {
        foreach ($app in $applist) {
            $AppName = $($app.name)
            Write-Host "$AppName has been detected for repair"
            if ($AppName -match "Microsoft Office Professional Plus 2010") {
                Set-Location "C:\Temp\MS_remove"
                Write-Host "Unable to repair Microsoft Office 2010. please manually repair or use the Office reinstall job"
            } else {
                if ($AppName -match "Microsoft Office Professional Plus 2013") {
                    Write-Host "Repairing Microsoft office 2013."
                    &  $Office2013 -ArgumentList $OfficeRepair
                } else {
                    Write-Host "Repairing Microsoft office 2016."
                    & $Office2016 -ArgumentList $OfficeRepair
                }
            }
        }
    } else {
        Write-Host "No application(s) detected for uninstall"
    }
}

. Repair-Office-Apps

产品的检测工作正常,因为我将其用于其他地方的卸载。运行PowerShell脚本时会出现安装程序可执行文件的帮助窗口,我不确定在传递命令行参数时我做错了什么。理想情况下,我希望将此命令作为作业传递并查询作业结果,但我认为最好先尝试构建基本命令。

0 个答案:

没有答案