Powershell 会话相关安装/更新模块
我有一个powershell脚本,用于安装/更新某些模块。如果第一次运行脚本,则会安装所需的模块,并每隔一段时间更新一次。在每次更新过程中,我都会收到以下警告:Powershell 会话相关安装/更新模块,powershell,Powershell,我有一个powershell脚本,用于安装/更新某些模块。如果第一次运行脚本,则会安装所需的模块,并每隔一段时间更新一次。在每次更新过程中,我都会收到以下警告: WARNING: The version '2.2.16' of module 'VSSetup' is currently in use. Retry the operation after closing the 应用程序 在执行脚本时,是否需要进行一些管理以解决此问题? 此脚本将在容器内定期执行,但不确定如何管理脚本内的会话。一
WARNING: The version '2.2.16' of module 'VSSetup' is currently in use. Retry the operation after closing the
应用程序
在执行脚本时,是否需要进行一些管理以解决此问题?
此脚本将在容器内定期执行,但不确定如何管理脚本内的会话。一些参考例子会有所帮助。代码如下:
function Install-Update-Modules
{
[CmdletBinding()]
[OutputType([Boolean])]
Param([parameter(Mandatory)]$ModuleList)
begin { $i = 0}
process
{
#get the list of modules to be installed as a pre-requisite
$modules = Get-Content -Path $ModuleList
foreach($module in $modules)
{
$i = $i+1
#check if the module is already installed or not
$installed = Get-InstalledModule -name $module -AllVersions
if($installed -eq $null)
{
Write-Progress -Activity "Installing $($module) ...." -Status "Progress: " -PercentComplete ($i/$modules.Count*100)
if(!(Find-Module -Name $module | Install-Module -Force -AllowClobber -Scope AllUsers))
{
Write-Host "Failed Installing Module $($module)" -ForegroundColor Red
$false
}
}
else
{
Write-Progress -Activity "Updating $($module) ...." -Status "Progress: " -PercentComplete ($i/$modules.Count*100)
Update-Module -Name $module -Scope AllUsers -Force
}
}
$true
}
}不要从Visual Studio调用该函数。从
powershell-NoProfile
session调用它。从未从Visual Studio调用过它。以管理员身份启动powershell命令行,定位到脚本所在的路径,然后按脚本名称调用