How do I dynamically create functions that are accessible in a parent scope?

后端 未结 4 694
囚心锁ツ
囚心锁ツ 2021-01-02 11:21

Here is an example:

function ChildF()
{
  #Creating new function dynamically
  $DynFEx =
@\"
  function DynF()
  {
    \"Hello DynF\"
  }
\"@
  Invoke-Expres         


        
4条回答
  •  伪装坚强ぢ
    2021-01-02 12:23

    Another option would be to use the Set-Item -Path function:global:ChildFunction -Value {...}

    Using Set-Item, you can pass either a string or a script block to value for the function's definition.

提交回复
热议问题