Score:0

Can't install SqlServer PowerShell module 21.1.18256: PackageManagement\Install-Package : Access is denied

us flag

I have servers which have no access to the Internet so I have an internal PSRepository. I've downloaded the current SqlServer module (21.1.18256) and published it to my internal repo. I've installed it on five servers. On the sixth, I get:

> Install-module -name SqlServer -Repository JLP -AllowClobber
PackageManagement\Install-Package : Access is denied
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exce
   ption
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetChildItemCommand,Mic
   rosoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

I've never seen this before and have no idea where to start.

I'm running PowerShell (5.1) as admin. Versions are:

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.4583
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.4583
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

UPDATE

I had older versions on my repo: 21.1.18121 and 21.0.17199. I tried installing and got the Access is Denied message. Then I tried 21.0.17199 using

Install-module -name SqlServer -Repository JLP -AllowClobber -RequiredVersion 21.0.17199

and it worked.

UPDATE 2

I have downloaded other versions to my repo and tried them.

21.0.17279 failed to install.
21.0.17262 failed to install.
21.0.17240 installed.
Kirk avatar
us flag
I experience the same thing. Oddly adding -Verbose to the command to see if I could troubleshoot further actually caused it to install. I don't like it, but in case it works for others I post it here.
Score:0
in flag

I would try this:

Install-Module -Name SqlServer -Scope CurrentUser

source: https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-7.1

If it works with your current login, then talk to someone about getting permission to update the local machine module folder.

user2871239 avatar
us flag
Good suggestion. Unfortunately, it gave me exactly the same error. I also tried that version of the command with PowerShell **not** running as Administrator with the same result.
in flag
Have you checked for write permission to folders in $env:PSModulePath? I would personally try installing the module to a different location to verify I can get it working then worry about installing to a default folder. https://docs.microsoft.com/en-us/powershell/scripting/developer/module/installing-a-powershell-module?view=powershell-7.1
user2871239 avatar
us flag
I haven't but I'm a local Administrator and running as Administrator so that **shouldn't** be an issue. Other people use the server and I don't want each person to have to install their own copy. Plus, I can install other modules using that format of command. And I've been able to install an earlier version.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.