I want to install the module Sqlserver in several devices by using a script powershell in Intune. It didn't work in few devices because it asks to install the package-provider. So I tried to add this step in my script.
I create a function that looks if the package is already installed, if not it get it. It has to be forced and has not to request the user to confirm the installation. Here is my function :
function Install-PackageProvider(
[string] [Parameter(Mandatory = $true)] $ModuleName
)
{
If(Get-PackageProvider| Where-Object {$_.Name -eq $ModuleName})
{
$Info = "The Package-Provider is already installed"
Write-Host $Info
}
else
{
Write-Host "We need to install the package provider. We start now"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
}
}
Unfortunately, it does not work for few devices and I get this error message where it can not identify a parameter corresponding to "Name". I try several things that I see on internet.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 ...
~~~~~
Anyone has an idea and can help me. The English is not my mother language, I hope that I did not do too many mistakes
Thank you
CodePudding user response:
I would try the following. It seems to work for me
function Install-PackageProvider(
[string] [Parameter(Mandatory = $true)] $ModuleName
)
{ If(Get-PackageProvider| Where-Object {$_.Name -eq $ModuleName})
{
$Info = "The Package-Provider is already installed"
Write-Host $Info
}
else
{
Write-Host "We need to install the package provider. We start now"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PackageManagement\Install-PackageProvider -Name $ModuleName -Force
}
}