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– DForck422018年12月20日 14:39:35 +00:00Commented 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– Kin Shah2018年12月20日 14:40:48 +00:00Commented 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 powershellDForck42– DForck422018年12月20日 14:43:11 +00:00Commented Dec 20, 2018 at 14:43
-
did you point your full
.psm1
path e.g. import-moduleC:\Program Files\WindowsPowerShell\Modules\get-serverAudit.psm1 -force
?Kin Shah– Kin Shah2018年12月20日 14:49:21 +00:00Commented 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 helpDForck42– DForck422018年12月20日 14:53:00 +00:00Commented 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.
Explore related questions
See similar questions with these tags.