-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathGet-Assoc.ps1
60 lines (53 loc) · 1.7 KB
/
Get-Assoc.ps1
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
55
56
57
58
59
60
function Get-Assoc {
<#
.SYNOPSIS
Displays file extension associations
.DESCRIPTION
Displays file extension associations which can be gotten from cmd.exe
.PARAMETER AsArray
Switch to return result as an array of objects as opposed to an ordered dictionary
.EXAMPLE
Get-Assoc
Name Value
---- -----
.EXAMPLE
Get-Assoc -AsArray | Where-Object { $_.Name -match 'xls' } | Select-Object Value, Name
Value Name
----- ----
Excel.Sheet.8 .xls
Excel.SheetBinaryMacroEnabled.12 .xlsb
Excelhtmlfile .xlshtml
Excel.SheetMacroEnabled.12 .xlsm
excelmhtmlfile .xlsmhtml
Excel.Sheet.12 .xlsx
#>
[CmdletBinding()]
param (
[switch] $AsArray
)
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
$CmdReturn = (cmd.exe /d /c assoc)
$GetAssoc = ([ordered] @{})
foreach ($CurItem in $CmdReturn) {
$Temp = $CurItem.Split('=')
$GetAssoc.Add($Temp[0], $Temp[1])
}
if ($AsArray) {
$ArrayOutput = $GetAssoc.GetEnumerator() | ForEach-Object {
new-object -TypeName psobject -Property ([ordered] @{
Extension = $_.Name
FType = $_.Value
})
}
Write-Output -InputObject $ArrayOutput
} else {
Write-Output -InputObject $GetAssoc
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}