using #requires in a powershell module (.psm1)

Welcome Forums General PowerShell Q&A using #requires in a powershell module (.psm1)

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 3 months ago.

  • Author
    Posts
  • #28576

    Participant
    Points: 0
    Rank: Member

    I am working on developing a powershell module that has dependencies on the activedirectory module supplied by Microsoft. I would like to have powershell not load the module if the activedirectory module is not present on the platform. It seems obvious that one would use #Requires -Modules ActiveDirectory for this purpose. This works great in standard powershell scripts (.ps1). It does not, however, seem to be adhered to by the import-module process. Am I missing something, or am I trying to do something that would be bad practice and should be done another way?

    Thanks

  • #28579

    Participant
    Points: 153
    Helping Hand
    Rank: Participant

    Prerequisites for importing the module are handled with Module Manifests. You can use New-ModuleManifest to assist in creating the manifest as well.

  • #28583

    Participant
    Points: 0
    Rank: Member

    Perfect Rob, that is exactly what I needed. Thanks for the insight.

The topic ‘using #requires in a powershell module (.psm1)’ is closed to new replies.