PsBananaUtils.HyperV.psm1

. "$PSScriptRoot\Public\Copy-FileToVirtualMachine.ps1"
. "$PSScriptRoot\Public\Enter-VirtualMachine.ps1"
. "$PSScriptRoot\Public\Get-VirtualMachineAliasesSetup.ps1"
. "$PSScriptRoot\Public\Get-VirtualMachinesInfo.ps1"
. "$PSScriptRoot\Public\Invoke-VirtualMachine.ps1"
. "$PSScriptRoot\Public\Register-VirtualMachineAliases.ps1"
. "$PSScriptRoot\Public\Start-VirtualMachine.ps1"
. "$PSScriptRoot\Public\Stop-VirtualMachine.ps1"
. "$PSScriptRoot\Public\Unregister-VirtualMachineAliases.ps1"
. "$PSScriptRoot\Public\Update-VirtualMachineAliases.ps1"

# User defined config
$Script:VirtualMachineManager = $null;

Register-ArgumentCompleter -CommandName Invoke-VirtualMachine -ParameterName Property -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    $ExcludedProps = @("VMName", "Credential", "FileSource")

    $already = @()
    if ($fakeBoundParameters.ContainsKey("Property")) {
        $already = $fakeBoundParameters["Property"] -split ","
    }

    $props = Get-Command -name Invoke-Command | Get-Member -MemberType Properties | Select-Object -Expand Name -Unique

    $props = $props |
    Where-Object { $_ -notin $ExcludedProps } |
    Where-Object { $_ -notin $already } |
    Where-Object { $_ -like "$wordToComplete*" }

    foreach ($p in $props) {
        [System.Management.Automation.CompletionResult]::new($p, $p, 'ParameterValue', $p)
    }
}

Register-ArgumentCompleter -CommandName Enter-VirtualMachine -ParameterName Property -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    $ExcludedProps = @("VMName", "Credential", "FileSource")

    $already = @()
    if ($fakeBoundParameters.ContainsKey("Property")) {
        $already = $fakeBoundParameters["Property"] -split ","
    }

    $props = Get-Command -name Enter-PSSession | Get-Member -MemberType Properties | Select-Object -Expand Name -Unique

    $props = $props |
    Where-Object { $_ -notin $ExcludedProps } |
    Where-Object { $_ -notin $already } |
    Where-Object { $_ -like "$wordToComplete*" }

    foreach ($p in $props) {
        [System.Management.Automation.CompletionResult]::new($p, $p, 'ParameterValue', $p)
    }
}

Register-ArgumentCompleter -CommandName Copy-FileToVirtualMachine -ParameterName Property -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    $ExcludedProps = @("VMName")

    $already = @()
    if ($fakeBoundParameters.ContainsKey("Property")) {
        $already = $fakeBoundParameters["Property"] -split ","
    }

    $props = Get-Command -name Copy-VMFile | Get-Member -MemberType Properties | Select-Object -Expand Name -Unique

    $props = $props |
    Where-Object { $_ -notin $ExcludedProps } |
    Where-Object { $_ -notin $already } |
    Where-Object { $_ -like "$wordToComplete*" }

    foreach ($p in $props) {
        [System.Management.Automation.CompletionResult]::new($p, $p, 'ParameterValue', $p)
    }
}

Register-ArgumentCompleter -CommandName Start-VirtualMachine -ParameterName Property -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    $ExcludedProps = @("VMName")

    $already = @()
    if ($fakeBoundParameters.ContainsKey("Property")) {
        $already = $fakeBoundParameters["Property"] -split ","
    }

    $props = Get-Command -name Start-VM | Get-Member -MemberType Properties | Select-Object -Expand Name -Unique

    $props = $props |
    Where-Object { $_ -notin $ExcludedProps } |
    Where-Object { $_ -notin $already } |
    Where-Object { $_ -like "$wordToComplete*" }

    foreach ($p in $props) {
        [System.Management.Automation.CompletionResult]::new($p, $p, 'ParameterValue', $p)
    }
}

Register-ArgumentCompleter -CommandName Stop-VirtualMachine -ParameterName Property -ScriptBlock {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)

    $ExcludedProps = @("VMName")

    $already = @()
    if ($fakeBoundParameters.ContainsKey("Property")) {
        $already = $fakeBoundParameters["Property"] -split ","
    }

    $props = Get-Command -name Stop-VM | Get-Member -MemberType Properties | Select-Object -Expand Name -Unique

    $props = $props |
    Where-Object { $_ -notin $ExcludedProps } |
    Where-Object { $_ -notin $already } |
    Where-Object { $_ -like "$wordToComplete*" }

    foreach ($p in $props) {
        [System.Management.Automation.CompletionResult]::new($p, $p, 'ParameterValue', $p)
    }
}

Export-ModuleMember -Function (Get-ChildItem "$PSScriptRoot\Public\*.ps1" -Recurse | ForEach-Object { $_.BaseName }) `
                    -Alias vmenter, vmguest, vmcopy, vmstart, vmstop