none
Difference dot sourcing and importing module RRS feed

Answers

  • dot sourcing runs the script in the global scope.

    Import-Module loads an assemble or module file.

    They are not in any way similar although theey can both be used to accomplish certain things.

    Start by reading the manual on what a module is.

    help about_modules

    Now look at how dot sourcing works.  A file loaded with dot sourcing is not executed but remains in memory.  A function in a PS1 and all variables will not remain in memory if you "run" the script without dot sourcing.

    search for "dot sourcing" and read almist any of the many blog articles on how to use it.


    \_(ツ)_/

    • Marked as answer by janhoedt Thursday, April 16, 2015 12:53 PM
    Thursday, April 16, 2015 12:41 PM

All replies

  • place all functions in one file and dot source file.

    place all functions in module and import them.

    What else would you expect?


    \_(ツ)_/

    Thursday, April 16, 2015 10:56 AM
  • >What else would you expect?
    Just as my questions stipulates: "Please clarify the difference "


    Jan Hoedt


    Or should I read "What else would you expect?"  as "there is no difference"?
    • Edited by janhoedt Thursday, April 16, 2015 11:59 AM Update
    Thursday, April 16, 2015 11:47 AM
  • dot sourcing runs the script in the global scope.

    Import-Module loads an assemble or module file.

    They are not in any way similar although theey can both be used to accomplish certain things.

    Start by reading the manual on what a module is.

    help about_modules

    Now look at how dot sourcing works.  A file loaded with dot sourcing is not executed but remains in memory.  A function in a PS1 and all variables will not remain in memory if you "run" the script without dot sourcing.

    search for "dot sourcing" and read almist any of the many blog articles on how to use it.


    \_(ツ)_/

    • Marked as answer by janhoedt Thursday, April 16, 2015 12:53 PM
    Thursday, April 16, 2015 12:41 PM