Debug-XboxMultiplayer.psm1

function Debug-XboxMultiplayer
{
    [CmdletBinding( )]
    Param()

    Begin
    {
    }
    Process
    {
    
    
        
        #Uninstall/reinstall the Teredo adapter - Not feasible, should be auto fixed in RS1
        #Check for disabled reg key: HKLM\System\CurrentControlSet\Services\Tcpip6\Parameters Value DisabledComponents Type REG_DWORD Preferred Value 0x0
        $currentTeredoRegistryValue = Get-Item "HKLM:\System\CurrentControlSet\Services\Tcpip6\Parameters"
        if ($currentTeredoRegistryValue.GetValue("DisabledComponents") -eq $null)
        {
            Write-Host "No DisabledComponents Value."
        }
        elseif ($currentTeredoRegistryValue.GetValue("DisabledComponents") -ne 0)
        {
            Write-Warning "DisabledComponents Value Not 0x0."
            Set-ItemProperty "HKLM:\System\CurrentControlSet\Services\Tcpip6\Parameters" -Name "DisabledComponents" -Value 0
        }
        else 
        {
            Write-Host "DisabledComponents value present but set to 0x0."
        }
        #Check service status for IP Helper Service
        #ToDo - Do we enumerate its dependent services and check them as well?
        $currentServiceInfo = Get-Service iphlpsvc
        if ($currentServiceInfo.StartType -ne 'Automatic')
        {
            Write-Warning "IP Helper Service not configured to Auto Start."
            Set-Service iphlpsvc -StartupType Automatic
        }
        if ($currentServiceInfo.Status -ne 'Running')
        {
            Write-Warning "IP Helper Service not running"
            Set-Service iphlpsvc -Status Running
        }
        #Set Teredo settings to default values (check for default values for type and servername)
        $currentTeredoConfig = Get-NetTeredoConfiguration
        if ($currentTeredoConfig.Type -ne 'Default' -or $currentTeredoConfig.ServerName -ne 'win10.ipv6.microsoft.com.')
        {
            Write-Warning "Teredo parameters not default, current values:" $currentTeredoConfig
            Reset-NetTeredoConfiguration
        }
        #Check hosts file for win10.ipv6.microsoft.com entries and comment them out
        $hostsFileInput = "$env:windir\System32\drivers\etc\hosts"
        $hostsFileOutput = "$env:windir\System32\drivers\etc\hosts"
        $hostsFile = get-content $hostsFileInput
        $hostsFile | foreach { 
            if ($_ -match 'win10.ipv6.microsoft.com*' -and $_ -notmatch '# Removed Entry For ') 
            { 
                "# Removed Entry For " + $matches[0]
                Write-Warning "hosts file entry found for win10.ipv6.microsoft.com."
            } 
            else 
            {
                $_
            }
        } | Out-File $hostsFileOutput -enc ascii
        #Check service status for IKE EXT, Xbox Live Auth Manager, Xbox Live Networking Service
        #IKEEXT Service - This defaults to Automatic start (Triggered) but that isn't supported in PowerShell
        #ToDo - Should we alter the service settings via Registry instead of just setting to native Automatic start?
        #ToDo - Do we enumerate its dependent services and check them as well?
        $currentServiceInfo = Get-Service IKEEXT
        if ($currentServiceInfo.StartType -ne 'Automatic')
        {
            Write-Warning "IKE and AuthIP IPsec Keying Modules Service not configured to Auto Start."
            Set-Service IKEEXT -StartupType Automatic
        }
        if ($currentServiceInfo.Status -ne 'Running')
        {
            Write-Warning "IKE and AuthIP IPsec Keying Modules Service not running."
            Set-Service IKEEXT -Status Running
        }
        #Xbox Live Auth Manager Service - This defaults to Manual start, so we're just going to make sure it's not set to Disabled
        $currentServiceInfo = Get-Service XblAuthManager
        if ($currentServiceInfo.StartType -eq 'Disabled')
        {
            Write-Warning "Xbox Live Auth Manager Service is set to Disabled."
            Set-Service XblAuthManager -StartupType Manual
        }
        #Xbox Live Networking Service - This defaults to Manual start, so we're just going to make sure it's not set to Disabled
        $currentServiceInfo = Get-Service XboxNetApiSvc
        if ($currentServiceInfo.StartType -eq 'Disabled')
        {
            Write-Warning "Xbox Live Networking Service is set to Disabled."
            Set-Service XboxNetApiSvc -StartupType Manual
        }

        #Windows Time
        #Check what network profile is active. If Public, prompt to switch to Private to enable UPnP.
        Get-NetConnectionProfile
        #Windows Firewall Status and Profile
        #Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
        #Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow
        #Future section for checking for AVM router via UPnP and possible check for Apple router via NAT-PMP
        #Check to see if the OpenVPN adapter is installed. If so, alert to the user and point to www.xbox.com/windows/QoS
        $pnpDeviceList = Get-PnpDevice
        $pnpDeviceList | ForEach-Object {
            if ($_.Name -match 'TAP-Windows Adapter*') 
            { 
                Write-Host "OpenVPN Network Adapter Present. This may cause issues with Teredo. Please visit www.xbox.com/windows/QoS for more details."
            } 
        }
        
        Write-Host "Debugging complete."

}
}