0

I have a Powershell module that I've written and uploaded to my SQL Server at C:\Program Files\WindowsPowerShell\Modules.I have a SQL Agent job with a powershell step that calls the module. This all works and has been working.

However, I recently made a change to the way the Powershell module works. I updated the code and uploaded it to the server, but SQL Server seems to be executing the outdated version of the code still, even though the file has been replaced.

Do I need to tell SQL Server or Powershell to "refresh" the module somehow? How can I do that?

CR241
1,5653 gold badges18 silver badges32 bronze badges
asked Dec 20, 2018 at 14:22

2 Answers 2

1

Do I need to tell SQL Server or Powershell to "refresh" the module somehow? How can I do that?

You can use import-module yourModuleName -Force.

answered Dec 20, 2018 at 14:36
5
  • i tried running "Import-module Get-ServerAudit -force" and got the error "the specified module was not loaded because no valid module file was found in any module directory" Commented Dec 20, 2018 at 14:39
  • get-ServerAudit I assume is a cmdlet not a module. You have to force reload your entire module so that the cmdlets are exposed. Commented Dec 20, 2018 at 14:40
  • get-serveraudit is a .psm1 that i wrote and dropped in the modules directory. sorry if i'm not giving you all of the information, i'm still really green when it comes to powershell Commented Dec 20, 2018 at 14:43
  • did you point your full .psm1 path e.g. import-module C:\Program Files\WindowsPowerShell\Modules\get-serverAudit.psm1 -force ? Commented Dec 20, 2018 at 14:49
  • yeah, i figured out that i am an idiot and posted an answer. thank you so much for your help Commented Dec 20, 2018 at 14:53
0

I figured it out. I had somehow renamed the folder from Get-ServerAudit to Get_ServerAudit, so powershell was treating the updated module as a new module.

Deleting the incorrectly named folders from the server, fixing the folder names, and copying over the updated files worked.

answered Dec 20, 2018 at 14:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.