Using Out-GridView -Wait but window closes anyway

Microsoft Windows
Post Reply
1011010101010111001
Posts: 4
Joined: 2021-Oct-28, 4:06 pm

Using Out-GridView -Wait but window closes anyway

Post by 1011010101010111001 »

My code does the following:

Code: Select all

Param(
    [Parameter(Mandatory=$true)]
    [string[]]
    $find
)

Set-Location C:\script

Write-Output "Searching..."

$folders = @(a list of folders)

$excluded = @(a list of folders)

$results = foreach ($folder in $folders) {
    Get-ChildItem $folder -Recurse -Exclude $excluded | Select-String -Pattern $find | select FileName, LineNumber, Path
}

$results | Out-GridView -Wait

I'm initiating that script from the (Windows) command line like so:

Code: Select all

powershell.exe -file C:\script\find.ps1 -find "something to fine"
Issue: Script runs find from ISE. But closes the Out-GridView GUI when run from a command line, even with -Wait.

What am I doin' wrong?
User avatar
Simon Sheppard
Posts: 49
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: Using Out-GridView -Wait but window closes anyway

Post by Simon Sheppard »

Add a PAUSE statement to the end to prevent the script from finishing, or run it from a PowerShell window with:

Code: Select all

C:\script\find.ps1 -find "something to fine"
Post Reply