-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-PowerShellGuide.ps1
62 lines (57 loc) · 2.9 KB
/
Get-PowerShellGuide.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
61
function Get-PowerShellGuide {
[CmdletBinding(DefaultParameterSetName='NoTopic')]
[Alias('Get-PSGuide')]
param(
[Parameter(Mandatory,ParameterSetName='Topic',ValueFromPipelineByPropertyName)]
[Alias('TopicName')]
[string]
$Topic
)
process {
if ($PSCmdlet.ParameterSetName -eq 'NoTopic') {
if (-not $script:CachedPowerShellGuide) {
$guideTopics =
Get-ChildItem -Path $PSScriptRoot -Filter Guide |
Get-ChildItem -Recurse |
Where-Object Extension -in '.md' |
Where-Object FullName -notlike '*_site*'
$guideTopics = @($(
# Collect all items into an input collection
$inputCollection =$($guideTopics)
# 'unroll' the collection by iterating over it once.
$filteredCollection = $inputCollection =
@(foreach ($in in $inputCollection) {
$in
})
# Walk over each item in the filtered collection
foreach ($item in $filteredCollection) {
# we set $this, $psItem, and $_ for ease-of-use.
$this = $_ = $psItem = $item
if ($item.value -and $item.value.pstypenames.insert) {
if ($item.value.pstypenames -notcontains 'PowerShell Guide Topic File') {
$item.value.pstypenames.insert(0, 'PowerShell Guide Topic File')
}
}
elseif ($item.pstypenames.insert -and $item.pstypenames -notcontains 'PowerShell Guide Topic File') {
$item.pstypenames.insert(0, 'PowerShell Guide Topic File')
}
$item
}
))
$myModuleVersion = $MyInvocation.MyCommand.ScriptBlock.Module.Version
$script:CachedPowerShellGuide = [PSCustomObject]@{
PSTypeName = 'PowerShell.Guide'
Version = $myModuleVersion
AllTopics = $guideTopics
AllDemos = $guideDemos
}
}
$script:CachedPowerShellGuide
}
if ($PSCmdlet.ParameterSetName -eq 'Topic') {
$psGuide = Get-PowerShellGuide
$psGuide.AllTopics |
Where-Object Aliases -like $Topic
}
}
}