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

**URL:** <https://forums.powershell.org/t/array-is-with-results-is-opening-in-powershell-ise-but-not-when-in-powershell/24827>\
**Category:** PowerShell Help\
**Created:** [October 2, 2024, 1:26pm UTC](https://forums.powershell.org/t/array-is-with-results-is-opening-in-powershell-ise-but-not-when-in-powershell/24827 "2024-10-02T13:26:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmoore5553](https://avatars.discourse-cdn.com/v4/letter/m/e68b1a/32.png) [@mmoore5553](https://forums.powershell.org/u/mmoore5553)\
**Post date:** [October 2, 2024, 1:26pm UTC](https://forums.powershell.org/t/array-is-with-results-is-opening-in-powershell-ise-but-not-when-in-powershell/24827/1 "2024-10-02T13:26:59Z")

</div>

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 ?

```auto
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"

```

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [October 3, 2024, 6:11am UTC](https://forums.powershell.org/t/array-is-with-results-is-opening-in-powershell-ise-but-not-when-in-powershell/24827/2 "2024-10-03T06:11:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 2, 2024, 6:12am UTC](https://forums.powershell.org/t/array-is-with-results-is-opening-in-powershell-ise-but-not-when-in-powershell/24827/3 "2024-11-02T06:12:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
