forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-FormatView.ps1
More file actions
54 lines (48 loc) · 2.07 KB
/
Copy pathGet-FormatView.ps1
File metadata and controls
54 lines (48 loc) · 2.07 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#display a listing of all defined formatting views
Function Get-FormatView {
[cmdletbinding()]
[alias("gfv")]
[OutputType("PSFormatView")]
Param(
[Parameter(HelpMessage = "Specify a typename such as System.Diagnostics.Process.",ValueFromPipeline)]
[ValidateNotNullorEmpty()]
[string]$TypeName = "*",
[Parameter(HelpMessage = "Specify the version of PowerShell this cmdlet uses for the formatting data. Enter a two digit number separated by a period.")]
[system.version]$PowerShellVersion = $PSversionTable.psversion
)
Begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)"
#a regular expression pattern to match on the format type
[regex]$rx = "Table|List|Wide|Custom"
} #begin
Process {
Try {
$data = Get-FormatData -Typename $Typename -PowerShellVersion $PowerShellVersion -errorAction Stop | Sort-Object -Property TypeName
}
Catch {
Throw $_
}
if ($data) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Found $($data.count) type definitions"
#$data | Out-String | Write-Verbose
foreach ($item in $data) {
#there might be a collection of typenames
foreach ($tn in $item.TypeNames) {
#$tn | out-string | write-verbose
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting formatting view for $($tn)"
foreach ($view in $item.FormatViewDefinition) {
[PSCustomObject]@{
PSTypename = "PSFormatView"
Format = $rx.Match($view.Control).value
Name = $view.name
Typename = $tn
}
}
} #foreach tn
} #foreach item
} #if data
} #process
End {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)"
} #end
} #close Get-FormatView