powershellimport-module

Import-module doesn't run more than once


I have a script that should copy over another script and run the module, however when I try to run this more than once, it just ends, without warning, no out-put/errors.

I have been working importing modules to help my script run better and to also simplify use.

$Script:Es = $PSScriptRoot + "\" + "Main Script.psm1"
$Script:Ma32 = "C:\Temp\Scripts2"
$Script:E2 = "\Main Script.psm1"
$Script:E3 = $Ma32 + $E2

Function Get-Check {
    if ( -Not (Test-Path -Path $Ma32 ) ) {
        New-Item -ItemType directory -Path $Ma32 |out-null
    }
}

Function Get-Run {
    copy-item $Es $Ma32
    Import-Module $E3 
}

Function St {
    Get-Check
    Get-Run
}

St

Solution

  • Thanks for all the answers, using -force resolves the issue.

    Import-Module $E3 -force