-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreate.ArgumentCompletion.ps1
More file actions
48 lines (35 loc) · 1.63 KB
/
Create.ArgumentCompletion.ps1
File metadata and controls
48 lines (35 loc) · 1.63 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
#region Creating Argument Completer
# Helper function to create argument completion results
function New-CompletionResult
{
param(
[Parameter(Mandatory)]
[string]$CompletionText,
[string]$ListItemText = $CompletionText,
[string]$ToolTip = $CompletionText
)
New-Object System.Management.Automation.CompletionResult $CompletionText, $ListItemText, 'ParameterValue', $ToolTip
}
# VM Name ############################################
# Function that populates Argument completion results for 'Get-VM -Name'
function VMNameCompletion
{
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Hyper-V\Get-VM -Name "$wordToComplete*" | ForEach-Object { New-CompletionResult -CompletionText $_.Name }
}
# Register Argument Completer
Register-ArgumentCompleter -CommandName Get-VM -ParameterName Name -ScriptBlock $function:VMNameCompletion
# Experience argument completion for -VMName <TAB>
Get-VM -Name
# VM Id ##############################################
# Function that populates Argument completion results for 'Get-VM -Id'
function VMIdCompletion
{
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Hyper-V\Get-VM -Name "$wordToComplete*" | ForEach-Object { New-CompletionResult -CompletionText $_.Id -ListItemText $_.Name -ToolTip $_.Status }
}
# Register Argument Completer
Register-ArgumentCompleter -CommandName Get-VM -ParameterName Id -ScriptBlock $function:VMIdCompletion
# Experience argument completion for -Id <TAB>
Get-VM -Id
#endregion Creating Argument Completer