none
Powershell function inside a string RRS feed

  • Question

  • This may seem strange but I am trying to store powershell functions in a SQL table.

    I can do the SQL part but when I try to import the functions stored inside a string I get nothing.

    For example:

    $test = "function hello() { write-host ""hello world"" }"
    $ps = New-Module -Name PS -ScriptBlock {$test} -AsCustomObject
    $ps | gm


    I get the following output:

       TypeName: System.Management.Automation.PSCustomObject

    Name        MemberType Definition                    
    ----        ---------- ----------                    
    Equals      Method     bool Equals(System.Object obj)
    GetHashCode Method     int GetHashCode()             
    GetType     Method     type GetType()                
    ToString    Method     string ToString()     

    No function


    Thursday, July 11, 2019 3:23 PM

Answers

  • $test = "function hello() { write-host ""hello world"" } hello"
    Invoke-Expression $test
    This might help.
    • Marked as answer by ukkaapie Thursday, July 11, 2019 3:47 PM
    Thursday, July 11, 2019 3:44 PM

All replies