Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created October 31, 2016 22:48
Show Gist options
  • Save bielawb/0735aa5d184ad9044031262ef68d61d3 to your computer and use it in GitHub Desktop.
Save bielawb/0735aa5d184ad9044031262ef68d61d3 to your computer and use it in GitHub Desktop.
Module that uses WMF5 completion for vmconnect wrapper.
class DopelnijVMke : System.Management.Automation.IArgumentCompleter {
[System.Collections.Generic.IEnumerable[System.Management.Automation.CompletionResult]] CompleteArgument(
[string]$commandName,
[string]$parameterName,
[string]$wordToComplete,
[System.Management.Automation.Language.CommandAst]$commandAst,
[System.Collections.IDictionary]$fakeBoundParameters
) {
return [System.Management.Automation.CompletionResult[]]@(
foreach ($vm in Get-VM -Name "$wordToComplete*") {
[System.Management.Automation.CompletionResult]::new(
$vm.Name,
$vm.Name,
[System.Management.Automation.CompletionResultType]::ParameterValue,
"Wirtualna maszyna $($vm.Name)"
)
}
)
}
}
function Show-VM {
param (
[ValidateNotNullOrEmpty()]
[ArgumentCompleter([DopelnijVMke])]
[string]$VMName = 'Mgmt',
[ValidateNotNullOrEmpty()]
[string]$ComputerName = $env:COMPUTERNAME
)
vmconnect.exe $ComputerName $VMName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment