How to get Out-GridView display to show from a GUI?

I am working on putting together a PowerShell GUI for some Helpdesk folks at my work and what I want to happen is when a button is clicked, I want the Out-GridView to display with the results.

However, it is not working the way I had intended, but it works just fine when running from the PowerShell ISE.

I am assuming then that when running PowerShell code from a GUI, Windows Forms locks in any external processes extraneous to its control? Therefore, I need to use a Windows Forms toolbox object instead like a textbox, etc?

If this is the case, which Windows Forms object should I use that would be the closest thing to Out-GridView?

Thank you

You might share a relevant chunk of code; I’ve never had a problem invoking Out-GridView from a WinForms script. Rolling your own GridView is extremely nontrivial.

$ListOutdatedSystems_Button_Click = {
	If ((Get-InstalledModule -Name 'ConfigurationManager') -eq $true)
{
	$SCCMDrive = (Get-PSDrive -PSProvider CMSite).Name
        
	Set-Location -Path "$($SCCMDrive):"

	Try
	{
		Get-CMCollectionMember -CollectionId 'PRI00408' | Select-Object -Property Name, UserName | Sort-Object -Property Name | Out-GridView -Title 'ENA Tool - SCCM O365 Deployment Notification' 
	}

	Catch
	{
		[System.Windows.MessageBox]::Show($_,'My GUI Tool',0,'Error')
	}
}

Else
{
		Try
		{
			Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1) -ErrorAction Stop

			Try
			{
				Get-InstalledModule -Name 'ConfigurationManager' -ErrorAction Stop
				
				$SCCMDrive = (Get-PSDrive -PSProvider CMSite).Name
        
				Set-Location -Path "$($SCCMDrive):"

				Try
				{
					Get-CMCollectionMember -CollectionId 'PRI00408' | Select-Object -Property Name, UserName | Sort-Object -Property Name | Out-GridView -Title 'My GUI Tool' 
				}

				Catch
				{
					[System.Windows.MessageBox]::Show($_,'My GUI Tool',0,'Error')
				}
			}
			
			Catch
			{
				[System.Windows.MessageBox]::Show($_,'My GUI Tool',0,'Error')
			}
		}

		Catch
		{
			[System.Windows.MessageBox]::Show($_,'My GUI Tool',0,'Error')
		}
	}

#endregion Step 3: List Outdated Systems

I don’t have SCCM so I can’t test this myself, but I’ve done exactly this with Get-Process and other “native” commands on more than one occasion. Worked fine.

Not sure what happened, but all of a sudden it’s working.

Something wonky, I suppose.

Thanks Don