Powershell - Not able to find module - powershell

I'm experiencing problems when (re)installing modules in PowerShell (see Screenshot link below). It has worked before as the module is already installed.
Screenshot error
Already tried the following:
Set-ExecutionPolicy: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-6
.Net Framework 4.7.2 is already installed: https://community.powerbi.com/t5/Developer/Unable-to-Connect-with-Power-BI-Service-using-PowerShell/td-p/483356
Repository change: Unable to find repository on Update-Module
I'm out of ideas / Google results. Any suggestions/ideas that I can try? Many thanks in advance.
Error in text:
PS C:\Windows\system32> Install-module MicrosoftPowerBIMgmt
WARNING: Source Location 'https://www.powershellgallery.com/api/v2/package/MicrosoftPowerBIMgmt/1.0.840' is not valid.
PackageManagement\Install-Package : Package 'MicrosoftPowerBIMgmt' failed to download.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\admin....werBIMgmt.nupkg:String) [Install-Package], Exception
+ FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Best regards

Seems like you have outdated version of PowerShellGet 1.0.0.1. Try this first (as admin) and then retry your update.
Update-Module PowerShellGet

Try running this
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Related

Publish-Module fails with NuGet.Build.Tasks.Pack.targets(198,5) error : Index was outside the bounds of the array

I've upgraded to dotnet sdk version 3.1 and am trying to publish my powershell module. I am using powershell 5.1.
I run the command:
Publish-Module -Path "C:\sources\myModules\InstallationUtils\" -NuGetApiKey "xxxxxxx" -Repository internal.packages.org"
and get the error:
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
Successfully created package
'C:\Users\xxxxxx\AppData\Local\Temp\158464074\myModules\InstallationUtils\InstallationUtils.1.4.8.nupkg'.
C:\Program Files\dotnet\sdk\3.1.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(198,5): error :
Index was outside the bounds of the array.
[C:\Users\xxxxxx\AppData\Local\Temp\469d7c83-6e1a-4366-b948-6a415b0279be\Temp.csproj]
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.1\PSModule.psm1:10944 char:17
+ ... Publish-PSArtifactUtility #PublishPSArtifactUtility_Param ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility
Is anyone have similar issues and managed to fix it?
thanks
I have a work around, which involves replacing the old version of version nuget.exe in
C:\Users\xxxxx\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
with the latest version of nuget.exe .
I found the work around on SQLDBAWithABeard but I am hoping that there is a better solution than this?

Trouble installing Powercli 11.x

Easing back into Windows after a 3-4 year MacOS hiatus. Powershell has come a long way but I am running into some errors I can't figure out here.
Every article I see on installing the newer PowerCLI is rather simple. Use a package manager to download/install it and off you run. Not for me, I'm getting the following error when trying to run Install-Module -Name VMware.PowerCLI:
PackageManagement\Install-Package : Unable to find dependent module(s) (VMware.VimAutomation.Cis.Core)
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9307 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (VMware.VimAutomation.Cis.Core:String) [Install-Package], Exception
+ FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
I have tried this on two Windows machines and even with Powershell Core on a Mac. Same issue every time. What am I missing and/or doing wrong?

Update-Module not finding PSGallery repo in script as a scheduled task

I have a scheduled task which runs an exported function from my PowerShell module which is hosted at powershellgallery.com. The function performs a check against the built-in PSGallery repository to see if a newer version is available and if so, update it.
I've noticed my module is not being updated as it should and to troubleshoot the issue I've redirected the output from two separate commands. First, to make sure the repository is 'visible' to the SYSTEM account running the task I run:
Get-PSRepository *>> c:\repo.log
This yields the following output:
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
So the SYSTEM account running the function as a scheduled task can 'see' the repo; no problem. Next, the function runs the Update-Module command as such:
Update-Module -Name $ProductName -Confirm:$false -Force -Verbose *>> c:\update.log
This yields the following output:
Checking for updates for module '[removed by me]'.
PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'. Use
Get-PSRepository to see all available repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:12546 char:20
+ ... $sid = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Lastly, I checked the module to make sure it is indeed associated with PSGallery by running:
Get-InstalledModule -Name $ProductName | fl
The output shows:
RepositorySourceLocation : https://www.powershellgallery.com/api/v2/
Repository : PSGallery
UPDATE: I decided to use the Install-Module with the -Force switch to 'update' the module instead as I couldn't get the other command to work. Oddly though, when I do a Get-InstalledModule -AllVersions I can clearly see a difference between a module installed interactively and one installed under the SYSTEM account (running as a scheduled task). Pay attention to the Repository column:
If I run the function interactively it works without issue.
If I run Find-Module -Name $ProductName from within the function it finds the module without issue.
Tried both solutions from other question to no avail...
Any idea why the Update-Module command can't find the repo??
I believe you are seeing the bug described in https://github.com/PowerShell/PowerShellGet/issues/349 . It's not really related to SYSTEM account. Simplest workaround until fixed version is released is to uninstall the module then reinstall it again. You should only have to do that once, and update-module should work thereafter.
UPDATE: This is resolved in newer builds of PowerShellGet.

powershell update-help fails

I just started to learn PowerShell from the Microsoft virtual academy and I was running one of the commands indicated. while on their end it worked mine did not. I did look around for a solution to this issue. I just don't know what went wrong. any tips will helpful for this new PowerShell learner.
PS C:\Windows\system32> Update-Help -Force
Update-Help : Failed to update Help for the module(s) 'WindowsUpdateProvider' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US. Make sure the
HelpInfoUri property in the module manifest is valid or check your network connection and then try the command again.
At line:1 char:1
+ Update-Help -Force
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Update-Help], Exception
+ FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand
PS C:\Windows\system32> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Agreed, that this should be a SuperUser post, but since it is here.
This sort of error common and in most cases expected.
Not all the help files, update as expected for various reasons, most of the time its do to the update link associated. As shown in your error message.
Many module either have no online updateable help or the URL has been removed.
These sorts of error can be safely ignored. They do not impact PS functionality or use.
Get-Module -ListAvailable | Where HelpInfoUri | Update-Help
Or if you want to see all the message going back and forth with this, do...
Update-Help -Force -Verbose -ErrorAction SilentlyContinue
# Results
VERBOSE: Resolving URI: "http://go.microsoft.com/fwlink/?linkid=390758"
VERBOSE: Your connection has been redirected to the following URI: "http://download.microsoft.com/download/0/1/C/01CCC594-2F13-40E8-98FE-185486228BF4/"
VERBOSE: Performing the operation "Update-Help" on target "CimCmdlets, Current Version: 5.0.0.0, Available Version: 5.0.0.0, UICulture: en-US".
If you want to see the full error message in a more human readable for, do this...
Update-Help -Force -Ea 0 -Ev ErrMsgDetail
$ErrorMsgDetail.Exception
Failed to update Help for the module(s) 'AnyBox' with UI culture(s) {en-US} : Unable to connect to Help content. The server on which Help content is stored might not be available.
Verify that the server is available, or wait until the server is back online, and then try the command again.
Failed to update Help for the module(s) 'HostNetworkingService, WindowsUpdateProvider' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US.
Make sure the HelpInfoUri property in the module manifest is valid or check your network connection and then try the command again.
Actually the problem might also be related to privileges. At least it was for me. On a default Windows 10 install, Update-Help would not work at all, nor did all the other versions with -Force or -ErrorAction.
It turned out, also according to the official online help, you need to be administrator to update the help for powershell <6.0 (which Windows 10 defaults to PS5.1). Starting a new PowerShell with admin privileges immediately removed the problems and I could also view the help as a non-admin.
TL;DR:
Open Powershell, paste the command below and run Update-Help and it should download all AVAILABLE help files:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
It will a give a red warning for the modules that did not have any help files like:
update-help : Failed to update Help for the module(s) 'ConfigDefender, ConfigDefenderPerformance, PSReadline,
WindowsUpdateProvider' with UI culture(s) {en-US} : Unable to retrieve the HelpInfo XML file for UI culture en-US.
Make sure the HelpInfoUri property in the module manifest is valid or check your network connection and then try the
command again.
At line:1 char:1
+ update-help
+ ~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Update-Help], Exception
+ FullyQualifiedErrorId : UnableToRetrieveHelpInfoXml,Microsoft.PowerShell.Commands.UpdateHelpCommand
Long story:
I was trying to find a module and install it:
Find-Module -Name AudioDeviceCmdlets
But it needs NuGet so it prompts to install it but it failed for me:
NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'$HOME\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import
the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
So I googled for a solution and found out that I need to paste this on Powershell:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
And the NuGet installed just fine, so I remember the issue I had with Update-Help, so I tried it and it worked, and now when I do for example Get-Help Get-Item the help is shown fully.
From Niels Weistra on answers.microsoft:
The solution mentioned above is a workaround, to solve your issue permanently
Open Powershell and check for supported protocols by using [Net.ServicePointManager]::SecurityProtocol
Run the following 2 cmdlets to set .NET Framework strong cryptography registry keys:
Set strong cryptography on 64 bit .Net Framework (version 4 and above):
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Set strong cryptography on 32 bit .Net Framework (version 4 and above):
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
Restart Powershell and check again for supported protocol by using [Net.ServicePointManager]::SecurityProtocol
Source:
https://answers.microsoft.com/en-us/windows/forum/all/trying-to-install-program-using-powershell-and/4c3ac2b2-ebd4-4b2a-a673-e283827da143
Install NuGet via PowerShell script
I am new to Powershell and found this fixed my problem.
reference link
Update-Help -Verbose -Force -ErrorAction SilentlyContinue

How do I correctly install the PowerShell MSOnline module in Windows 8.1 Enterprise?

I'm trying to write some scripts for Azure Active Directory / Office online, and I'm completely unable to install the MSOnline powershell module. I've installed the Office Sign In Assistant version 7.2 (64-bit for my 64-bit machine). When I try to run the MSI installer for the PowerShell module, it says it can't find the sign in assistant. When I install the powershell module through PowerShellGet, and then run the commands, it fails with:
Connect-MsolService : The Microsoft Online Services Module is not configured properly. Please uninstall and then reinstall the module.
At line:1 char:1
+ Connect-MsolService
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], InvalidConfigurationException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.InvalidConfigurationException,Microsoft.Online.Administration.Automation.ConnectMsolService
Connect-MsolService : Object reference not set to an instance of an object.
At line:1 char:1
+ Connect-MsolService
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Connect-MsolService], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.Online.Administration.Automation.ConnectMsolService
Is there any way to get this installed ? I've even changed the language of my system to US-English and installed the correct language pack (because I've run into issues before with things not installing correctly if the system language is not US English)
Found at least a partial answer here that worked (at least got the module working again for one of my accounts, the other one still fails and remains a mystery):
MSOnline can't be imported on PowerShell (Connect-MsolService error)
In my case, some registry keys were missing (I don't know why) and reinstalling didn't help. I imported the registry keys with one path adaption from another system and now it works. I used the following registry keys (just copy to a file powershell.reg, change InstallPath if necessary, and import):
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSOnlinePowerShell]
"Version"="1.0.0"
"InstallPath"="c:\\Program Files\\WindowsPowerShell\\Modules\\MSOnline\\1.0\\"
"InstallLanguage"="en-us"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSOnlinePowerShell\Path]
"WebServiceUrl"="https://provisioningapi.microsoftonline.com/provisioningwebservice.svc"
"FederationProviderIdentifier"="microsoftonline.com"
Follow the steps to install the Azure AD Module here