pwsh/Get-PipeList.ps1
using namespace System.Runtime.InteropServices Set-Alias -Name pipelist -Value Get-PipeList function Get-PipeList { [CmdletBinding()]param() process { New-Delegate kernel32 { sfh CreateFileW([buf, int, IO.FileShare, ptr, IO.FileMode, int, ptr]) } New-Delegate ntdll { int NtQueryDirectoryFile([sfh, ptr, ptr, ptr, buf, ptr, uint, uint, bool, ptr, bool]) } if (($pipes = $kernel32.CreateFileW.Invoke( [buf].Uni('\\.\pipe\'), 0x80000000, [IO.FileShare]::Read, [IntPtr]::Zero, [IO.FileMode]::Open, 0, [IntPtr]::Zero )).IsInvalid) { throw [InvalidOperationException]::new('\\.\pipe\ is unavailable.') } $query, $isb = $true, [Byte[]]::new([IntPtr]::Size * 2) # IO_STATUS_BLOCK try { $dir = [Marshal]::AllocHGlobal(0x1000) $res = while (1) { if ($ntdll.NtQueryDirectoryFile.Invoke( $pipes, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero, $isb, $dir, 0x1000, 1, $false, [IntPtr]::Zero, $query ) -ne 0) { break } $tmp = $dir while (1) { $fdi = Read-DataValues -Handle $tmp -Map I2l6I2 [PSCustomObject]@{ PipeName = [Marshal]::PtrToStringUni([ptr].Mov($tmp, 0x40), $fdi[9] / 2) Instances = $fdi[6] # EndOfFile MaxInstances = [BitConverter]::ToInt32( [BitConverter]::GetBytes($fdi[7])[0..3], 0 # AllocationSize ) } if (!$fdi[0]) { break } $tmp = [ptr].Mov($tmp, $fdi[0]) } $query = $false } } catch { Write-Verbose $_ } finally { if ($dir) { [Marshal]::FreeHGlobal($dir) } } $pipes.Dispose() Write-Verbose "$($pipes.IsClosed)" if ($res) { Format-Table -InputObject $res -AutoSize } else { Write-Verbose 'Can not retrieve pipe names.' } } } Export-ModuleMember -Alias pipelist -Function Get-PipeList |