Show window titles

Displays the titles of all visible windows running in the user session
Version 1.0.1
Created on 2019-01-13
Modified on 2019-01-13
Created by Guy Leech
Downloads: 521

The Script Copy Script Copied to clipboard
<#
    Show Window titles for processes. Must run as the user owning the session otherwise window information is not available

    @guyrleech 2019
#>

if( ! $args -or ! $args.Count )
{
    Throw 'Must pass the session id as the only parameter'
}

[int]$thisSessionId = $args[0] -as [int]

[int]$outputWidth = 400

# Altering the size of the PS Buffer
$PSWindow = (Get-Host).UI.RawUI
$WideDimensions = $PSWindow.BufferSize
$WideDimensions.Width = $outputWidth
$PSWindow.BufferSize = $WideDimensions

[array]$processes = @( Get-Process | Where-Object {  $_.SessionId -eq $thisSessionId -and $_.MainWindowTitle } )

if( $processes -and $processes.Count )
{
    $processes | Format-Table -AutoSize -Property Id,ProcessName,MainWindowTitle,FileVersion,StartTime
}
else
{
    Write-Warning "No processes with window titles found in session id $thisSessionId"
}