Test-XboxSecurityEnabled.ps1

function Test-XboxSecurityEnabled {
    <#
    .Synopsis
        Queries whether secure connections are enabled or disabled.
    .Description
        Queries whether secure connections are enabled or disabled.
    .Example
        Test-XboxSecurityEnabled
    #>

    param(
    [Parameter(ValueFromPipelineByPropertyName=$true)]
    [Alias('DebugIPAddress')]
    [String[]]
    $Console
    )

    process {
        $ProcessBlock = {
            $xbox = $_
            $name = $xbox.Name
            $debugIP = $xbox.DebugIPAddress
            [bool]$Enabled = $false
            $result = $xbdm::SetXBoxNameNoRegister($debugIP)
            $result = ($xbdm)::DmIsSecurityEnabled([ref]$Enabled)
            if ($result -ne $script:XbdmSuccess) {
                Write-Error $xbdm::DmTranslateError($result)
            } else {            
                New-Object PSObject -Property @{
                    Secured =  $Enabled 
                    Console = $name
                    DebugIPAddress =$debugIP 
                }    
            }
            $result = $xbdm::SetXBoxNameNoRegister($null)
            if ($result -ne $script:XbdmSuccess) {
                Write-Error $xbdm::DmTranslateError($result)
                return
            }            
        }
        if ($Console) {
            $Console | 
                Connect-Xbox | 
                ForEach-Object $ProcessBlock
        } else {
            Get-Xbox | ForEach-Object $ProcessBlock
        }
    }
}