forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-PSScriptTools.ps1
More file actions
155 lines (125 loc) · 4.98 KB
/
Copy pathGet-PSScriptTools.ps1
File metadata and controls
155 lines (125 loc) · 4.98 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#display a summary of tools in this module
#I am deviating slightly from the singular noun naming convention because I am thinking of
#PSScriptTools as a singular thing, like a toolbox.
Function Get-PSScriptTools {
[cmdletbinding()]
[OutputType('PSScriptTool')]
Param(
[Parameter(HelpMessage = 'Filter commands based on a standard verb.')]
[string]$Verb
)
Write-Verbose "Starting $($MyInvocation.MyCommand)"
$thisCmd = Get-Command $MyInvocation.MyCommand
$ThisModule = $thisCmd.Source
$thisVersion = $thisCmd.version.ToString()
Write-Verbose "Using version $thisVersion"
$h = @"
___ ___ ___ _ _ _____ _
| _ \ __/ __|__ _ _(_)_ __| |__ _|__ ___| |___
| _\__ \__ \ _| '_| | '_ \ _|| |/ _ \ _ \ (_-<
|_| |___/___\__|_| |_|_.__/\__||_|\___\___/_/__/
|_| |_|
v$ThisVersion
"@
#ConvertTo-ASCIIArt has been removed from the module 4/4/2022
#ignore and suppress errors to create the ASCII art since this is optional and decorative only
#$h = ConvertTo-ASCIIArt $ThisModule -font small -ErrorAction SilentlyContinue
# $h+= "`n"
#$h += ConvertTo-ASCIIArt $thisVersion -Font small -ErrorAction SilentlyContinue
if ($host.name -match 'console|code') {
"$([char]27)[1;38;5;177m$h$([char]27)[0m" | Write-Host
}
else {
Write-Host $h
}
#Write-Host $h -ForegroundColor Yellow
Write-Verbose "Getting PSScriptTool data $ThisModule"
$ModuleFunctions = Get-Content -path $ToolDataPath | ConvertFrom-Json
if ($Verb) {
$ModuleFunctions = $ModuleFunctions.where{ $_.verb -match $Verb }
Write-Verbose "Found $($ModuleFunctions.count) functions matching your criteria"
}
foreach ($fun in $ModuleFunctions) {
[PSCustomObject]@{
PSTypeName = 'PSScriptTool'
Name = $fun.Name
Alias = $fun.Alias
Verb = $fun.verb #$fun.split("-")[0]
Synopsis = $fun.Synopsis
Version = $fun.version -as [version]
}
}
Write-Verbose "Ending $($MyInvocation.MyCommand)"
}
#define an argument completer for the Verb parameter
Register-ArgumentCompleter -CommandName Get-PSScriptTools -ParameterName Verb -ScriptBlock {
param($commandName, $parameterName, $WordToComplete, $commandAst, $fakeBoundParameter)
#PowerShell code to populate $WordToComplete
Get-Verb | Where-Object { $_.verb -like "$WordToComplete*" } |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_.verb, $_.verb, 'ParameterValue', $_.group)
}
}
<#
Previous version
Function Get-PSScriptTools {
[cmdletbinding()]
[OutputType('PSScriptTool')]
Param(
[Parameter(HelpMessage = 'Filter commands based on a standard verb.')]
[string]$Verb
)
Write-Verbose "Starting $($MyInvocation.MyCommand)"
$thisCmd = Get-Command $MyInvocation.MyCommand
$ThisModule = $thisCmd.Source
$thisVersion = $thisCmd.version.ToString()
Write-Verbose "Using version $thisVersion"
$PSBoundParameters.Module = $ThisModule
Write-Verbose 'Using these bound parameters'
$PSBoundParameters | Out-String | Write-Verbose
$h = @"
___ ___ ___ _ _ _____ _
| _ \ __/ __|__ _ _(_)_ __| |__ _|__ ___| |___
| _\__ \__ \ _| '_| | '_ \ _|| |/ _ \ _ \ (_-<
|_| |___/___\__|_| |_|_.__/\__||_|\___\___/_/__/
|_| |_|
v$ThisVersion
"@
#ConvertTo-ASCIIArt has been removed from the module 4/4/2022
#ignore and suppress errors to create the ASCII art since this is optional and decorative only
#$h = ConvertTo-ASCIIArt $ThisModule -font small -ErrorAction SilentlyContinue
# $h+= "`n"
#$h += ConvertTo-ASCIIArt $thisVersion -Font small -ErrorAction SilentlyContinue
if ($host.name -match 'console|code') {
"$([char]27)[1;38;5;177m$h$([char]27)[0m" | Write-Host
}
else {
Write-Host $h
}
#Write-Host $h -ForegroundColor Yellow
Write-Verbose "Getting exported functions from $ThisModule"
#Using Get-Module instead of Get-Command -module which wants to include private functions
$ModuleFunctions = ((Get-Module $ThisModule).ExportedFunctions).values
if ($Verb) {
$ModuleFunctions = $ModuleFunctions.where{ $_.verb -match $Verb }
}
Write-Verbose "Found $($ModuleFunctions.count) functions matching your criteria"
#get all aliases once
$allAliases = Get-Alias
foreach ($fun in $ModuleFunctions) {
Write-Verbose "Processing $fun"
#find a matching alias
$alias = $allAliases.where({ $_.ReferencedCommand.name -eq $fun }).name
Write-Verbose "Detected alias $alias"
[PSCustomObject]@{
PSTypeName = 'PSScriptTool'
Name = $fun
Alias = $alias
Verb = $fun.verb #$fun.split("-")[0]
Synopsis = (Get-Help $fun.name).synopsis
Version = $fun.version
}
}
Write-Verbose "Ending $($MyInvocation.MyCommand)"
}
#>