-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathGet-ProcessWindowStatus.ps1
More file actions
30 lines (30 loc) · 940 Bytes
/
Get-ProcessWindowStatus.ps1
File metadata and controls
30 lines (30 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Add-Type -AssemblyName UIAutomationClient
function Get-ProcessState
{
<#
Written by: http://vcloud-lab.com
Last Edit: 06-July-2020
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$ProcessName = 'Notepad'
)
Begin
{
Add-Type -AssemblyName UIAutomationClient
}
process
{
$processList = Get-Process -Name $ProcessName
foreach ($process in $processList)
{
$automationElement = [System.Windows.Automation.AutomationElement]::FromHandle($process.MainWindowHandle)
$processPattern = $automationElement.GetCurrentPattern([System.Windows.Automation.WindowPatternIdentifiers]::Pattern)
[PSCustomObject]@{
Process = $process.MainWindowTitle
ProcessState = $processPattern.Current.WindowVisualState
}
}
}
}