-
Notifications
You must be signed in to change notification settings - Fork 6
/
autocompleters.ps1
64 lines (51 loc) · 2.3 KB
/
autocompleters.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
62
63
64
Register-ArgumentCompleter -CommandName Get-PSRemoteOperationResult, New-PSRemoteOperation -ParameterName Computername -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$names = (Get-ChildItem -Path $PSRemoteOpArchive | Split-Path -leaf).foreach( { $_.split("_")[0].toUpper() }) | Get-Unique
if ($wordToComplete) {
$fill = $names | Where-Object { $_ -match "$wordToComplete" }
}
else {
$fill = $names
}
$fill | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -CommandName Wait-PSRemoteOperation, Get-PSRemoteOperation -ParameterName Computername -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
$names = (Get-ChildItem -Path $PSRemoteOpPath -file | Split-Path -leaf).foreach( { $_.split("_")[0].toUpper() }) | Get-Unique
if ($wordToComplete) {
$fill = $names | Where-Object { $_ -match "$wordToComplete" }
}
else {
$fill = $names
}
$fill | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
Register-ArgumentCompleter -CommandName New-PSRemoteOperation -ParameterName To -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
(Get-ChildItem -Path Cert:\CurrentUser\my -DocumentEncryptionCert).Subject |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
<#
Test for the json file with remote op path settings and prompt the user to run Register-PSRemoteOpPath if not found
#>
$json = Join-Path -path $PSScriptRoot -ChildPath psremoteoppath.json
if (Test-Path $json) {
Import-PSRemoteOpPath -path $json
}
else {
$msg = @"
No PSRemoteOpPath settings file was found to import. The module will be easier to use
if you set global variables for `$PSRemoteOpPath and `$PSRemoteOpArchive. Run the
commmand Register-PSRemoteOpPath. If you've recently updated the module through the
PowerShell Gallery, you might need to re-register the paths.
If you prefer to set the values in your profile script you can ignore this
warning.
"@
Write-Warning $msg
}