简体   繁体   English

仅安装PowerShell PackageProvider和Module(如果尚未安装)

[英]Only install PowerShell PackageProvider and Module if not already installed

I have running the following Powershell script as part of an Octopus Deploy. 我已经将以下Powershell脚本作为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  

Something like this should work: 这样的事情应该起作用:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Powershell 4 中安装 Powershell 模块? - how to install a Powershell module in Powershell 4? 无法在 Powershell 中安装 SQLServer 模块 - Cannot install SQLServer module in Powershell Powershell SQL Server模块2017手动安装 - Powershell sql server module 2017 manual install 我是否需要单独安装sql server 2008,因为Visual Studio 2010已经安装了Express Edition? - Do I need to install sql server 2008 separately as the express edition is already installed with Visual Studio 2010? sql server 2005命令行安装错误ADD_LOCAL属性已安装 - sql server 2005 command line install error ADD_LOCAL property already installed SQL Powershell 模块未安装在您的代理计算机上。 请按照以下步骤执行此任务 - SQL Powershell Module is not installed on your agent machine. Please follow steps given below to execute this task 我已经安装了“ install-dbatools” powershell脚本,但是没有copy-sqllogin或export-sqllogin函数 - I have installed the “install-dbatools” powershell script, but there is no copy-sqllogin or export-sqllogin function 是否可以在 Windows 10 上同时安装 SQLPS 和 SqlServer PowerShell 模块? - Is it possible to install both SQLPS and SqlServer PowerShell module on Windows 10? 为多个已安装的过程打开带引号的标识符 - Turning on Quoted Identifiers for multiple already installed procedures 使用PowerShell安装SQL Server - Install SQL Server using PowerShell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM