0

I'll preface this by saying I am not an expert powershell user by any means, so I'm probably going about this the wrong way.

I have a module that I am working on regularly and I update / tweak it often. It is stored in C:\Users\-user-\Documents\WindowsPowerShell\Modules if that matters.

Currently I have to close the powershell window and reopen a new one if I want the new / updated methods to be accessible - even when I perform an import in the same window that I am executing commands in.

I have tried doing . $profile but this does nothing. Do I need to add the module to the profile?

1
  • 1
    Remove-Module moduleName -Force; Import-Module moduleName Commented Oct 15, 2017 at 4:15

2 Answers 2

2

An alternative to removing and adding the module would be simply Import-Module myModule -Force:

-Force [< SwitchParameter >]

Indicates that this cmdlet re-imports a module and its members, even if the module or its members have an access mode of read-only.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked a charm! Thanks @ManuelBatsching
1

You can simply unload the module and then load it again.

As we can see in Microsoft's documentation:

Remove-Module

The Remove-Module cmdlet removes the members of a module, such as cmdlets and functions, from the current session.

Import-Module

The Import-Module cmdlet adds one or more modules to the current session. The modules that you import must be installed on the local computer or a remote computer.

Here's a code for example:

# Unload the Module
PS > Remove-Module myModule -Force

# Load it again
PS > Import-Module myModule 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.