本文介绍了如果尚未安装,仅安装 PowerShell PackageProvider 和 Module的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为 Octopus 部署的一部分,我运行了以下 Powershell 脚本.

I have running the following Powershell script as part of an Octopus Deploy.

但是,如果它们尚未安装,我只希望它们安装.

However, I only want them to install if they are not already installed.

我已经安装了它们,最好它也只在低于某个版本时才安装它们.

I they are installed, preferably it would also only install them if they are below a certain version.

有人可以建议这样做的最佳方法是什么吗?

Can someone advise what is considered to be the best approach for doing this?

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Confirm:$False -Force

Install-Module -Name SqlServer -AllowClobber -Confirm:$False -Force

推荐答案

这样的事情应该可行:

if (Get-Module -ListAvailable -Name SqlServer) {
    Write-Host "SQL Already Installed"
}
else {
    try {
        Install-Module -Name SqlServer -AllowClobber -Confirm:$False -Force
    }
    catch [Exception] {
        $_.message
        exit
    }
}


if ((Get-PackageProvider -Name NuGet).version -lt 2.8.5.201 ) {
    try {
        Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Confirm:$False -Force
    }
    catch [Exception]{
        $_.message
        exit
    }
}
else {
    Write-Host "Version of NuGet installed = " (Get-PackageProvider -Name NuGet).version
}

这篇关于如果尚未安装,仅安装 PowerShell PackageProvider 和 Module的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:49
查看更多