Modules vs. Scripts: It’s Not Just the Letter ‘M’
Here’s an interesting gotcha if you are spawning a new window for asynchronous execution via the "cmd.exe /c start" hack. This works as expected in a script, but doesn’t work in a module.
$start = get-date
cmd /c start powershell -command "start-sleep 20"
write-host "$([int]((get-date) - $start).TotalSeconds) seconds";
Even odder, you can Import-Module Example.ps1 and have it come back immediately after powershell initialization. However, if you Import-Module Example.ps***M***1, it will block until the cmd.exe process finishes.
I tried to come up with a rationale for why this works in a .ps1 but not in a .psm1, but...I got nuthin'