Powershell: add new cmdlet set-module to modify code in module on the fly

Created on 8 Feb 2020  路  3Comments  路  Source: PowerShell/PowerShell

steps to reproduce


import-module ./foobar.psm1

get-foobar
# hello

set-module -name foobar -RemoveFunction get-foobar,set-foobar -AddCode {
  $a='hello foobar'
  function show-foobar {
     $a
  }
}

get-foobar
# ERROR

show-foobar
#hello foobar

its possible to do this with

. $module {
 # code
}

but it more powershell way to create cmdlet

Issue-Question Resolution-Answered WG-Engine

Most helpful comment

I don't think we should encourage users to be modifying modules in-session.

It's useful for debugging on occasion, but I have't seen anywhere near enough compelling use cases to make it a standard cmdlet.

All 3 comments

I don't think we should encourage users to be modifying modules in-session.

It's useful for debugging on occasion, but I have't seen anywhere near enough compelling use cases to make it a standard cmdlet.

Updated module a developer can load with Force parameter. In general modules can have complex session state dependencies and changing module code/variables can destroy the session. If we think about binary modules it is absolutely impossible to change anything.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings