Input Box Pop-up
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$Value = [Microsoft.VisualBasic.Interaction]::InputBox("Enter a value", "Title", $null)
Details
Displays a pop-up box that prompts the user to enter a value. The value entered is then saved to a variable in the script.
  |  
Out-GridView for VS Code

Out-GridView is a great tool for quickly creating selection dialogs or displaying information that you sort. However, when using it in Visual Studio Code (VS Code), it tends to display the grid window behind the VS Code window. So, in an effort to prevent me from having to click my mouse one more time, I created the function Out-GridViewCode. This function uses all the parameters as the standard Out-GridView, just add some extra functionality to ensure the grid window is the active one. When using the Out-GridView it will automatically bring the grid windows to the front. If you use the -PassThru or -Wait parameters Out-GridView does not release control until the windows is closed. So, in this situation the function will minimize the VS Code window allowing the grid window to be displayed. Then once the grid window is closed, VS Code will restore itself.

Note: This is designed for use with PowerShell 5 and below. It does not provide a replacement for the lack of Out-GridView in PowerShell Core 6.0. That fix is coming in PowerShell 7.0.


Function Out-GridViewCode{
<#    
.SYNOPSIS
    Sends output to an interactive table in a separate window. With extended support to display Out-GridView as main window when using VS Code
    
.DESCRIPTION
    The Out-GridView cmdlet sends the output from a command to a grid view window where the output is displayed in an interactive table. However, when you use VS Code the window appears in the background. Running this wrapper will bring the window to the front. 
	
	Parameters remain the same as the orginal Out-GridView
    
.PARAMETER InputObject
        Accepts input for Out-GridView.
            
.PARAMETER Title 
        Specifies the text that appears in the title bar of the Out-GridView window.
        
.PARAMETER OutputMode 
        Send items from the interactive window down the pipeline as input to other commands. By default, this cmdlet does not generate any output. To send items from the interactive window down the pipeline, click to select the items and then click OK.
		
.PARAMETER PassThru
        Indicates that the cmdlet sends items from the interactive window down the pipeline as input to other commands. By default, this cmdlet does not generate any output. This parameter is equivalent to using the Multiple value of the OutputMode parameter.
        
.PARAMETER Wait
        Indicates that the cmdlet suppresses the command prompt and prevents Windows PowerShell from closing until the Out-GridView window is closed. By default, the command prompt returns when the Out-GridView window opens.
#>
    [CmdletBinding(DefaultParameterSetName = 'PassThru')]
    Param(
        [Parameter(ValueFromPipeline = $true)]
        [PSObject[]]$InputObject,
        
        [Parameter(Mandatory=$false)]
        [string]$Title,

        [Parameter(ParameterSetName = "Wait")]
        [switch]$Wait,
        
        [Parameter(ParameterSetName = "OutputMode")]
        [Microsoft.PowerShell.Commands.OutputModeOption]$OutputMode,
        
        [Parameter(ParameterSetName = "PassThru")]
        [switch]$PassThru
    )
    Begin{
        # Create output list object
        [System.Collections.Generic.List[PSObject]] $OutputObject = @()

        # Load windows control and get VS Code process infomation
        $sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
        Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
        $processes = Get-Process -Name Code,powershell

        # Build parameter object to splat later on
        $GridViewParams = @{}
        $PSBoundParameters.GetEnumerator() | Where-Object {$_.Key -ne 'InputObject'} | ForEach-Object{
            $GridViewParams.Add($_.Key,$_.Value)
        }
    }
    Process{
        # Load each item to the Output object. This is done to handle pipeline values
        $InputObject | ForEach-Object{ $OutputObject.Add($_) }
    }
    End{
        # if wait or passthru minimize VS Code window
        # since the process does not release we go ahead and minimize
        # VS code so the grid windows appears
        if($Wait -or $PassThru){
            foreach($proc in $processes){
                $hwnd = @($proc)[0].MainWindowHandle
                [Win32.NativeMethods]::ShowWindowAsync($hwnd, 2) | Out-Null
            }
        } 
        
        # display out-gridview
        $OutputObject | Out-GridView @GridViewParams

        # if wait or passthru restore VS Code window
        # else bring grid to the front
        if($Wait -or $PassThru){
            foreach($proc in $processes){
                $hwnd = @($proc)[0].MainWindowHandle
                [Win32.NativeMethods]::ShowWindowAsync($hwnd, 3) | Out-Null
            }
        } else {
            Get-Process -Name powershell | Where-Object {$_.MainWindowTitle.Trim() -eq '$OutputObject | Out-GridView @GridViewParams' -or
                $_.MainWindowTitle.Trim() -eq $title} | ForEach-Object{
                    $hwnd = @($_)[0].MainWindowHandle
                    [Win32.NativeMethods]::ShowWindowAsync($hwnd, 2) | Out-Null
                    [Win32.NativeMethods]::ShowWindowAsync($hwnd, 10) | Out-Null
                }
        }
    } 
}

Yes/No Prompt
$yes = new-Object System.Management.Automation.Host.ChoiceDescription "&Yes","help"
$no = new-Object System.Management.Automation.Host.ChoiceDescription "&No","help"
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no)
$answer = $host.ui.PromptForChoice("Prompt","Click yes to continue",$choices,0)

if($answer -eq 0){
    Write-Host "You clicked Yes"
}elseif($answer -eq 1){
    Write-Host "You clicked No"
}
Details
Creates a Yes/No prompt and provides an example of taking actions based on the answer selected.
  |  |