Get-Xbox.ps1

function Get-Xbox
{
    <#
    .Synopsis
        Gets the currently connected xboxes from Xbox Neighborhood or connects to a new xbox
    .Description
        Gets the currently connected xboxes from Xbox Neighborhood or connects to a new xbox
    .Example
        Get-Xbox
        # Gets all of the xboxes from Xbox Neighborhood
    .Example
        Get-Xbox MyConsole
        # Connects to MyConsole
    .Example
        Get-Xbox MyConsoleGroup
        # Connects to MyConsoleGroup. To Manipulate console groups, use ... Set/Add/Remove/Clear/Store/Load-Console
    #>

    param(
    [Parameter(
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true)]
    [String[]]
    $Console,
    
    [Switch]
    $DoNotConnect
    ) 
    
    begin {
        Set-StrictMode -Off
        if (-not (Test-Path Variable:\XapXboxManager)) {
            $Script:XapXboxManager = New-Object Xdevkit.XboxManagerClass
        }
        $existingGroups = @{}
        if ((Test-Path $psScriptRoot\XBPSConsoleGroup.clixml)) {
            $existingGroups = Import-Clixml $psScriptRoot\XBPSConsoleGroup.clixml
        }
        $groups = @{} + $existingGroups
    }    
        
    process {
        if (-not $Console) { 
            if ($groups -and $groups.Default) {
                $console = "Default"
            } else {
                $Console = $script:XapXboxManager.Consoles -split ' ' | Select-Object -First 1 -Unique                
            }
        }
        if (-not $Console) {
            throw "No default console to connect to. Add a default console in Xbox Neighborhood or use Add-Xbox -Console CONSOLENAME -Group Default to add a console to the default group"
        }
        if ($DoNotConnect) {
            $Console            
        } else {
            Connect-Xbox $Console
        }
    }
}