[英]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.