Hi,
I’ve written several custom PowerShell modules recently which provide wrappers around some az and mggraph commands. For some reason these modules are very slow to import. Like 50 seconds or so. The modules themselves only have 1 exported funciton and maybe 10-20 private functions all in one big file.
When I run import-moodule MYModule -verbose, all of the slowness appears to be before it exports the functions.
I tried removing the RequiredModules from the manifest, thinking this was slowing it, but it didn’t make a difference.
Is there a way of troubleshooting this slowness?
Here is a copy of the manifest and root module file:
Manifest
@{
# Script module or binary module file associated with this manifest.
RootModule = ‘ManageAzRbac.psm1’# Modules that must be imported into the global environment prior to importing this module RequiredModules = @( 'Az.Accounts', 'Az.Resources', 'Az.ResourceGraph' ) # Version number of this module. ModuleVersion = '1.2.0' # ID used to uniquely identify this module GUID = '789287d1-02ff-4886-b2bd-c8c5171d4a8e' # Author of this module Author = 'Jeremy Hagan' # Company or vendor of this module CompanyName = 'Company Dot Com' # Description of the functionality provided by this module Description = 'Module to create and manage Access Group and Role Assignments in Azure' # Functions to export from this module FunctionsToExport = @('Set-AzRbac') # Cmdlets to export from this module CmdletsToExport = @() # Variables to export from this module VariablesToExport = @() # Aliases to export from this module AliasesToExport = @() # Private data to pass to the module specified in RootModule/ModuleToProcess PrivateData = @{ }
}
Root Module
Dot source all public functions
Get-ChildItem -Path $PSScriptRoot\Public*.ps1 | ForEach-Object { . $_.FullName }
Dot source all private functions
Get-ChildItem -Path $PSScriptRoot\Private*.ps1 | ForEach-Object { . $_.FullName }