Search code examples
powershellmodulestartupimport-module

How can I import PowerShell module at the time of system startup?


I want my custom PowerShell module (.dll) to be imported at the time of system start-up.

There is a way to write import-module MODULE-PATH in $profile file. so that whenever we launch PowerShell it gets imported. But if some other program is calling powershell.exe with any command-let from our custom module then it may not use profile.

Is there any way by which we can import our custom module so that any user/program can use the command-lets from it?


Solution

  • Perhaps because you didn't fill the correct profile file. Look at :

    $profile.AllUsersAllHosts
    C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
    

    instead of :

    $profile.AllUsersCurrentHost
    C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
    
    $profile.CurrentUserAllHosts
    C:\Users\JPB\Documents\WindowsPowerShell\profile.ps1
    
    $profile.CurrentUserCurrentHost
    C:\Users\JPB\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1