Question About Import-Module

Welcome Forums General PowerShell Q&A Question About Import-Module

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

Tee
 
Participant
2 years, 2 months ago.

  • Author
    Posts
  • #53934
    Tee

    Participant
    Points: 0
    Rank: Member

    I was wondering if I could get some clarification about something. I have a bat file that calls a powershell script using the ExecutionPolicy of bypass. Anyhow, in my script I'm doing a import-module on PSExcel.psd1. As a developer, I like to clean up after myself once I'm finished with my processing. I know when you use Import-Module that module is available only during that session so I'm assuming calling Import-module for each call to my script is okay. However, I'm wondering if I should do a remove-module at the end of my script just as a good practice. Any input on this? Should I not worry about calling remove-module or should I?

  • #53945

    Keymaster
    Points: 1,638
    Helping HandTeam Member
    Rank: Community Hero

    No need at all. Even if you import the same module over and over, all you'll get is a warning saying it was already done, and PowerShell manages its scopes quite well.

    • #53957
      Tee

      Participant
      Points: 0
      Rank: Member

      Thanks Don. That's what I thought.

The topic ‘Question About Import-Module’ is closed to new replies.