PowerShell Import-Module vs Dot Sourcing

前端 未结 3 1145
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 02:38

If I want to separate out some of my functionality from my main PowerShell script, I can either write that as a .ps1 file and dot source the same or I can create th

3条回答
  •  孤独总比滥情好
    2021-02-01 03:30

    Dotsourcing + script and modules are 2 different things. Modules are great to collect/group functions and cmdlets that you would use in a script. If you have functions that you want to use interactively(you call a function in a console), then module can be a great fit.

    If you have one big script that you run to .. let's say "migrate a file share", or a single script that you call regulary using Task Scheduler, then dot-sourcing easier.

    It depends on what you need. Summary:

    • If you just use the the functions/scripts in THIS situation(script/job) = use dot source.
    • If you use common functions/script that are used in other scripts too OR you want to call some of the functions interactively etc. = use module.

提交回复
热议问题