Trace-XboxMultiplayer.psm1

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

    Begin
    {
    }
    Process
    {
        $LocalPath = Split-Path -parent $PSCommandPath
        $DiagPath = $LocalPath + "\Logging\XboxNetAPIDiagWindows.exe"
        $Date = Get-Date
        $File = "$LocalPath" + "\Logging\" + $Date.ToFileTimeUtc()
        $Directory = New-Item -ItemType Directory -Force -Path $File -Verbose

        $StartTraceFile = $Directory.FullName + "\start_of_session.etl"
        $TraceFile = $Directory.FullName + "\trace.etl"
        $DuringTraceFile = $Directory.FullName + "\during_session.etl"
        $StopTraceFile = $Directory.FullName + "\stop_session.etl"
        $GIPFile = $Directory.FullName + "\GIP.xml"
        $Teredo = $Directory.FullName + "\Teredo.txt"
        $SystemInfo = $Directory.FullName + "\SystemInfo.txt"

        set starttracefile=$StartTraceFile 
        set tracefile=$TraceFile 
        set duringtracefile=$DuringTraceFile 
        set stoptracefile=$TraceFile 

        Write-Host "Snapping current firewall configuration. This may take some time..."     
        & $DiagPath -out $StartTraceFile -etwstart $TraceFile -xrn > $VerboseOutput
     
        Write-Host "Snap complete." 

        Write-Host "***************************************************************" -ForegroundColor Black -BackgroundColor White
        Write-Host "********************* Start the scenario ********************" -ForegroundColor Black -BackgroundColor White
        Write-Host "***************************************************************" -ForegroundColor Black -BackgroundColor White
        Read-Host "Tracing has started. Try your multiplayer or party chat scenario now. Please press ENTER when something BAD happens and we'll snap the current state."

        & $DiagPath -out $DuringTraceFile > $VerboseOutput

        gip -All -Detailed | Export-Clixml $GIPFile
        systeminfo > $SystemInfo
        netsh int teredo show state > $Teredo

        Write-Host "Snap complete."
        Read-Host "Press ENTER to stop the trace."

        & $DiagPath -out $StopTraceFile -etwstop $TraceFile -xrn > $VerboseOutput
        $DirectorySimple = $Directory.FullName
        Write-Host "Logs are saved at $DirectorySimple"

}
}