Array is with results is opening in powershell ISE but not when in powershell

I am not sure why the array is not opening up at the end of the script. I can open powershell ISE as an admin and it opens the gui after getting the results. If i save the script to the computer and then just right click and open with powershell I never get the gui part. I get the results.

what am I missing ?

if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }


Set-ExecutionPolicy -ExecutionPolicy Unrestricted


Function Get-Folder($initialDirectory="")

{
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null

    $foldername = New-Object System.Windows.Forms.FolderBrowserDialog
    $foldername.Description = "Select a folder"
    $foldername.rootfolder = "MyComputer"
    $foldername.SelectedPath = $initialDirectory

    if($foldername.ShowDialog() -eq "OK")
    {
        $folder += $foldername.SelectedPath
    }
    return $folder
}

$UPDLocation = Get-Folder

## Define the array which will be used to create the hash table
$vhdarray = @()

## Get list of all VHDs and all Open VHDs for comparison
$vhds = gci $UPDLocation | Where-Object {($_.Name -like "*.vhdx") -and ($_.name -notlike "*template*")}

$openfiles = get-smbopenfile | where {$_.path -Like "*.vhdx"}

## Check list of VHDs against open VHDs to determine if the disk is connected to on of the hosts
foreach($vhd in $vhds)
    {
    $openfiletest = ($openfiles | Where {$_.path -eq $vhd.FullName}) | select -Unique
    IF ($openfiletest)
        {
        $vhdopened = $true
        $vhdrdshostip = $openfiletest.clientcomputername | select -Unique
        $vhdrdshost = ([System.Net.Dns]::gethostentry($vhdrdshostip)).hostname
        }
    ELSE 
        {
        $vhdopened = $false
        $vhdrdshost = "Not Connected"
        }

## Get user SID from VHD file name - then convert SID to username
    $usersid = ([io.path]::GetFileNameWithoutExtension($vhd.Name)).trim("UVHD-")
    $objSID = $Null
    try {
        $objSID = (New-Object System.Security.Principal.SecurityIdentifier ($usersid) -ErrorAction SilentlyContinue)
    $objSID = $objSID.Translate([System.Security.Principal.NTAccount])
        } 
    catch {
        Write-Host "SID Not Translated - $usersid"
        }    

## Order the data into a hash table and add to the array
    $hash = [ordered]@{
        'Username' = $objSID.Value
        'VHD Connected' = $vhdopened
        'RDS Host' = $vhdrdshost
        'VHD Path' = $vhd.FullName
        'VHD Last Write' = $vhd.LastWriteTime
        'VHD Size (MB)' = $vhd.Length/1MB
        }
    
    $vhdproperties = New-Object -TypeName PSObject -Property $hash
    $vhdarray += $vhdproperties
    }

$timestamp = get-date -f MM-dd-yyyy_HH_mm_ss
$vhdarray | sort Username | Export-Csv C:\users\public\Desktop\UPDReport_$timestamp.csv
write-host -ForegroundColor DarkCyan "Report Saved at C:\admin.ssd\UPDReport_$timestamp.csv"
$vhdarray | sort username | ogv -Title "VHD List"

try not running it that way. Open powershell, then call the path to the script and it will probably work.
I’m not at a computer to replicate but my guess is when you right-click and run in powershell it doesnt bother waiting for you to interact with Out-Gridview (don’t use aliases btw) and instead just completes script execution