Using CSV File in Module

I would like one of my internal functions to import a CSV file that exists within the module directory. What’s the best way to do this?

I see there’s a spot in the module manifest file where I can include the CSV file in the file list. But how would I go about accessing that file?

Thanks!

There’s a magic variable called $MyInvocation that has a number of properties you can access, including the location of the current script. We cover it pretty well in “The PowerShell Scripting and Toolmaking Book,” if you have that. Given that location, you just use Import-CSV or whatever.

Thanks Don. I checked out MyInvocation, but it didn’t have the properties I was after.

However, I just found a property of the module itself called $MyModule.ModuleBase that gives me the path to the module directory. From there I can check for the CSV file within that directory:

$module = Import-Module MyModule -passthru
Test-Path -Path "$($module.modulebase)\mycustomfile.csv"