Page 1 of 1

Using Out-GridView -Wait but window closes anyway

Posted: 2021-Oct-28, 4:16 pm
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?

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

Posted: 2021-Oct-29, 6:39 am
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"