PowerShell One-Liner to Locate Scripts and Automatically Open them in New Tabs in the ISE

I recently wrote a blog about how to find scripts where you had accomplished some specific task. That blog article was titled “How do I find that PowerShell Script where I did __________?

What if you not only want to find those scripts, but also open them automatically in new tabs in the PowerShell ISE? It just so happens that you’re in luck:

I went ahead and piped the results to Out-Null because I didn’t want anything returned at the command line. As you can see, there were three scripts that were automatically opened in new tabs in the PowerShell ISE:

ise-tabs1a

The one-liner shown above was a direct copy and paste from the previously referenced blog article, but you could also expand the “Path” property to make it a little cleaner:

These scripts could of course return a lot of results, more than you would want to try to open in new tabs in the ISE so you could only open them if say there’s no more than a dozen results, otherwise return a warning and the results at the command line:

ise-tabs1b

The magic of opening a script in a new tab in the PowerShell ISE is with this command:

µ

2 Comments

  1. Brett

    I did something similar. However, I used the Out-Gridview -passthru to display them for selection; I can select as many as I like. In the future, I would also like to parse the first line of the function’s help and display that as well.

    function Get-FunctionFileName
    {
    [CmdletBinding()]

    param ($Name)
    $Start = $PWD
    $ArrayofPaths = @( $env:PSModulePath -split ‘;’)
    $Collection = @()

    $Name = $Name -replace ‘\.\\’, ”
    $Name = $Name -replace ‘\.ps1′,”

    foreach ($dir in $ArrayofPaths)
    {
    Set-Location -Path $dir
    $Collection += Get-ChildItem -Recurse -File -path “*$Name*.ps1”
    }

    $Results = $Collection | Select-Object -Property LastWriteTime, Length, Fullname, @{N=’Module’;E={Split-Path -Path $_.Directory -Leaf }}
    $Selection = $Results | Out-GridView -PassThru -Title ‘Boss, Genius Idea! Look at these functions! ‘

    if ( $Selection -eq $null ) {
    break
    }

    foreach ( $item in $Selection ) {
    psEdit $item.FullName
    }
    }

    Reply

Leave a Reply

%d bloggers like this: