Powershell Install-Module ImportExcel - unable to find module providers

I’m trying to use ImportExcel for the first time.

this is in the first few lines of my script:

using namespace system.collections.generic
Add-Type -AssemblyName System.Data.OracleClient
Install-Module -Name ImportExcel -Scope CurrentUser -Force  #this was just added...gives the following error

error from Install-Module line:

PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).

this is my new function below that:

Function Process_ErrorDescMap{
    [cmdletbinding()]
      Param ([string]$errorCodeListFilePath)
      Process
      {
            # import excel file and show in gridview (make sure file exists!)
            Import-Excel -Path $errorCodeListFilePath | Out-GridView
            $errorCodeList = Import-Excel -Path errorCodeListFilePath #| Where-Object 'Month Number' -eq 12 | Group-Object -Property Country -NoElement | Sort-Object -Property Count -Descending

            Break ###############################################################
            return $errorCodeList #list of error codes
      } #end Process
    }# End of Function Process_ErrorDescMap

This is my main code area below that…

$deviceErrDescMap = Process_ErrorDescMap -errorCodeListFilePath $errorCodeListFile
#plan is to filter output further like commented out part in function $errorCodeList line

So what am I doing wrong with this Install-Package? I hope I can do it at the top of my script (running in vs code), and not a command line thing. I’d hate to think that everyone that runs this needs to do something at the command line.

I’m looking at these examples:

importExcel

Import excel data

reading writing excel files

Update:
I’m trying this:
Find-Module -Name PowerShellGet | Install-Module -Scope CurrentUser -Force
Which gives error:

PackageManagement\Find-Package : Unable to find module providers (PowerShellGet).

I saw unable to find module

It seems like the article is saying to delete the OneDrive\Documents\WindowsPowerShell\Modules\PackageManagement folder. Will that uninstall other things I’ve installed and cause other issues? I’m not sure if I’m using Find-Module/Install-Module incorrectly, and that’s causing the error, or something else I need to fix.

I think the first thing to suggest is not to use Install-Module as part of your script. You’re going to want to run it everytime the script runs. Better to install the module separately then use

#Requires -Modules ImportExcel

at the top of your script to make sure it meets the requirements.

What is the output of Get-Module PowerShellGet | Format-List when run in a PowerShell prompt?

1 Like

Path : C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1
Description : PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Modules, DSC Resources, Role Capabilities and Scripts.
ModuleType : Script
Version : 1.0.0.1
NestedModules : {}
ExportedFunctions : {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
ExportedCmdlets :
ExportedVariables :
ExportedAliases : {fimo, inmo, pumo, upmo}

I’m leaning towards import-csv now

Before you delete the folder from OneDrive, what’s the output of

Get-PSRepository

PackageManagement\Get-PackageSource : Unable to find module providers (PowerShellGet).

I’d go with your intitial thought and move the PackageManagement folder out of your OneDrive documents folder - just move it somewhere else for now, don’t delete it entirely until you’re happy you don’t need to move it back.

From what I’ve read, this is a consequence of letting VSCode update the PackageManagement module; moving the PackageManagement folder should not affect anything else you’ve installed.

PowerShell seems to lock the folder, so make sure you close all your sessions (console, ISE, VSCode) before you try and move it.

1 Like

Good idea Matt. I’m giving it a try.

I moved the folder elsewhere, and when I went into VSCode it said my PackageManagement wasn’t up to the latest and asked if I wanted to install latest so I said yes. I still didn’t seem to have ImportExcel, so I added Install-Module -Name ImportExcel -Scope CurrentUser -Force at the top of my function, which gives the same error:

PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).

Should I move the PackageManagement folder and not install latest when I open VSCode? Am I using Install-Module wrong?

I would:

Close all instances of PowerShell (console, ISE, VSCode)
Move the PackageManagement folder from OneDrive
Open a PowerShell Console (Run As Administrator)
Run Install-Module ImportExcel

Forget about doing it in your script or in VSCode for now and troubleshoot package management in the console.

2 Likes

I ran Install-Module ImportExcel and it ran fine with VSCode closed, PackageManagement dir moved out, and at Powershell prompt only (I forgot to be admin). I opened VSCode and let it get the updated PackageManagement like it always asks to do. Then I let it

Import-Excel -Path $path | Out-GridView

in my function, and get this error:

Failed importing the Excel workbook > ‘C:\Data\Views\EndToEnd_view\ServiceEndToEnd\ErrorCodeList\Error Code List.xlsx’ with worksheet ‘’: No column headers found on

top row ‘1’. If column headers in the worksheet are not a requirement then please use the ‘-NoHeader’ or ‘-HeaderName’ parameter.

I thought that I didn’t have to specify -Header or -NoHeader. I wouldn’t want to specify header names like -Header requires, because the SDK one is weird and has carriage return in it.

I was reading possible regression issue ImportExcel, and as far as I can see, they say I have to give the header names in ‘’ after -Header.

Any thoughts?

If it has headers, you shouldn’t need to do either. If it doesn’t have headers, you need to either specify -NoHeader or -HeaderName and specify the headers.

1 Like

It definitely has the column header. I’m not sure if there’s a formatting thing to look into to see if it’s not in the format needed, but opening the spreadsheet, it has column names with the data below.

Also, there’s only one worksheet, and I’m not really giving the name of the worksheet, but I don’t think that’s needed, looking at ImportExcel examples

Is the column header definitely on row 1? It being at the top of the column, doesn’t automatically make it the header; it must be on the very first row of the spreadsheet for it to work automatically. If the column headers are actually on row 2 because Margaret in accounts likes to make row 1 half the height and fill it in yellow, then you need to do:

Import-Excel $path -StartRow 2
1 Like

wow! You’re right! I hadn’t seen it actually starts on row 2. I’ll try that. Thank you!!! :slight_smile: :grin:

so once I have it imported, how do I do a lookup in the data to find the Conditions for error value when sdk row is 1200? I’m trying this, and it doesn’t like the $_.‘’ part.

$ConditionForErr = $importedExcel | Where-Object ‘SDK status code’ -eq 4013 | $_.‘Conditions that detect error’

You can use it in a similar way to Import-CSV whereby every row is an object.

If this is my spreadsheet:

FirstName Surname
Willow Rosenberg
Buffy Summers
Xander Harris
Tara Maclay
Joyce Summers
Rupert Giles

Let’s say I want the first name of all the people with the surname Summers.

$excelData  = Import-Excel Names.xlsx
$firstNames = $excelData | 
    Where-Object {$_.Surname -eq 'Summers'} | 
        Select-Object -ExpandProperty FirstName
$firstNames 
1 Like

It’s always Margaret!!

1 Like