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?

2 Answers 2


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.

  • 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"
    – DForck42
    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.
    – Kin Shah
    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
    – DForck42
    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 ?
    – Kin Shah
    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
    – DForck42
    Dec 20, 2018 at 14:53

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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.