Passing a function result for parameter list?

This topic contains 3 replies, has 3 voices, and was last updated by  Mark Smith 1 month ago.

  • Author
    Posts
  • #89498

    Mark Smith
    Participant

    Good evening all!

    I have a database and two functions.

    In the database, I have a table that holds all log entries from PS scripts I run and tie in logging. Typically, that table's record will have an entry like this:

    TimeStamp | ScriptName | Action | Result | Notes | System (for computer touched by the script).

    I have a function created that will list for me all scripts listed in that table that have run in the last month. It's basically called, "FUNCTION List-LoggedScripts". If I run this script, I'll get a result like:

    ScriptName
    ———-
    New-NICSetting
    Find-UserDetails
    Find-MissingSystems

    Those results, above, are the scripts, again, that have been run in the last month.

    I have a second function that will allow me to pull the logs from the last run of a script. This script is called "Get-LatestLogs". It's structured something like this:

    FUNCTION Get-LatestLogs ($scriptName){
    
    CODE FOR GOING AND GETTING LATEST LOG ENTRIES FROM 
    
    }
    

    Instead of typing in a $scriptName answer explicitly, I'll like to be able to pikc from the results of the first function List-LoggedScripts at the time that I run the command, seeing the options from a drop down when I type:

    Get-LatestLogs -scriptName DROPDOWNHERE

    I have Googled to no avail. I see where you can add an array, but not create an array from a function and add it on the fly.

    Possible? Help?

    Thanks for anything ya'll can offer.

    Mark

  • #89500

    John Steele
    Participant

    If I understand your scenario correctly, Out-Gridview -PassThru might be what you're looking for. This will let you choose the scripts from your first function and send it out.

    Consider the small example below:

    function ProcessDropDown($process) {
    
        Write-Warning "You chose process: $($process.Name)"
    }
    
    ProcessDropDown(Get-Process | Out-GridView -PassThru)
    

    Running that code and choosing the Powershell process will give you the following output:

    WARNING: You chose process: powershell
    
  • #89512

    Sam Boutros
    Participant

    Mark, you didn't find what you're looking for because you didn't know what it's called. It's called 'Dynamic Parameter'.
    Here's a script that shows about how to do this, and I'm sure that now you know what to google for you'll find a lot more info online. Please post your progress..

    • #89620

      Mark Smith
      Participant

      This is what I was looking for. Took me a quick minute to figure out how to implement according to my needs but it's up and running as needed now. Thank you!

You must be logged in to reply to this topic.