This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
#Requires -PSEdition Desktop | |
function GenHostOptions () { | |
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes', 'Yes' | |
$No = New-Object System.Management.Automation.Host.ChoiceDescription '&No', 'No' | |
$options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No) | |
$title = 'Teams Network Assesment Tool' | |
$message = "Do you want to proceed downloading and installing tool?" | |
$result = $host.ui.PromptForChoice($title, $message, $options, 0) | |
switch ($result ) { | |
0 { $true } | |
1 { $false } | |
Default { "wrong option" } | |
} | |
} | |
$Ok = $true | |
$NetworkAssessmentTool = "C:\Program Files (x86)\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe.config" | |
Write-Host "Checking if tool exist in default path" | |
$NetworkAssessmentToolExist = test-Path $NetworkAssessmentTool | |
if (-not $NetworkAssessmentToolExist) { | |
#exist go furhter | |
Write-Information "Microsoft Teams Network Assessment Tool not detected" | |
if (GenHostOptions) { | |
try { Invoke-WebRequest -uri "https://download.microsoft.com/download/e/0/2/e026d13b-9b1b-472a-b322-616c6e6d9c19/MicrosoftTeamsNetworkAssessmentTool.exe" -OutFile "$env:userprofile\Downloads\MicrosoftTeamsNetworkAssessmentTool.exe" } | |
catch { | |
write-host "Error downloading tool" | |
$ok = $false | |
} | |
Write-Host "Starting installer process." | |
try { | |
invoke-Command -scriptblock { &"$env:userprofile\Downloads\MicrosoftTeamsNetworkAssessmentTool.exe" "/install" "/quiet" "/passive" "/norestart" } | |
} | |
catch { | |
$ok = $false | |
write-host "Error installing tool" | |
break | |
} | |
do { | |
Write-Host "waiting installer process to finish." | |
Start-Sleep -Seconds 5 | |
} | |
while ((Get-Process MicrosoftTeamsNetworkAssessmentTool -ErrorAction silentlycontinue | measure).Count -gt 0) | |
} | |
else { | |
Write-Host "exiting!" | |
$ok = $false | |
break | |
} | |
} | |
else{} | |
if ((test-Path $NetworkAssessmentTool) ) | |
{ | |
try { | |
Write-Host "Changing media duration time" | |
[xml]$x = Get-Content -Path $NetworkAssessmentTool | |
$x.configuration.appSettings.add[9].value = "65535" | |
$x.save($NetworkAssessmentTool) | |
} | |
catch { | |
Write-Host "Failed Changing media duration time" | |
$ok = $false | |
} | |
} | |
else { | |
#expecting tool to be installed, if not exit | |
Write-Host "Tool had not been installed, stopping process" | |
$ok = $false | |
break | |
} | |
if ($ok) { | |
if ((Get-NetFirewallRule -DisplayName "NetworkAssessmentTool.exe" -ErrorAction SilentlyContinue | measure).Count -eq 0) { | |
Write-Host "No relevant rule detected. Creating new set" | |
new-NetFirewallRule -Name "NetworkAssessmentTool.exe-UDP" -Direction Inbound -DisplayName "NetworkAssessmentTool.exe" ` | |
-Enabled "True" -Profile "any" -Protocol UDP -Program "C:\Program Files (x86)\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe" -EdgeTraversalPolicy DeferToUser -Action Allow | out-null | |
new-NetFirewallRule -Name "NetworkAssessmentTool.exe-TCP" -Direction Inbound -DisplayName "NetworkAssessmentTool.exe" ` | |
-Enabled "True" -Profile "any" -Protocol TCP -Program "C:\Program Files (x86)\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe" -EdgeTraversalPolicy DeferToUser -Action Allow | out-null | |
} | |
$currentCulture = (Get-Culture).Name | |
#change culture before opening another instance | |
Set-Culture -CultureInfo en-US | |
[scriptblock] $ScriptBlock0 = { & 'C:\Program Files (x86)\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe'; if ($?) { exit } } | |
$command1 = ("-Command {0}" -f $ScriptBlock0 -replace "'", "`'") | |
write-host "Starting Relay Connectivity Check " | |
Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit", $command1 -Wait | |
if ( | |
( get-content (Get-ChildItem -Path "$env:localappdata\Microsoft Teams Network Assessment Tool\" -Filter *_service_connectivity_check_results.txt | sort -Descending LastWriteTime )[0].FullName ) -contains "Service verifications completed successfully" | |
) { | |
[scriptblock] $ScriptBlock = { Invoke-Command -scriptblock { & 'C:\Program Files (x86)\Microsoft Teams Network Assessment Tool\NetworkAssessmentTool.exe' '/qualitycheck'; if ($?) { exit } } } | |
$command = ("-Command {0}" -f $ScriptBlock -replace "'", "`'") | |
Write-Host "Starting NetworkAssessmentTool in new session with en-US culture" | |
Start-Process $PSHOME\powershell.exe -ArgumentList "-NoExit", $command -Wait | |
Set-Culture -CultureInfo $currentCulture | |
explorer "$env:localappdata\Microsoft Teams Network Assessment Tool\"; | |
} | |
else { | |
write-host "initial connectivity test failed. must contain 'Service verifications completed successfully'" | |
} | |
} | |
else { | |
write-host "stopping" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment