forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancel-performance.ps1
110 lines (93 loc) · 3.1 KB
/
cancel-performance.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<#
.SYNOPSIS
This script cleans up after a perf run
.PARAMETER Remote
The remote to connect to. Must have ssh remoting enabled, and public key auth. username@ip
#>
param (
[Parameter(Mandatory = $false)]
[string]$Remote = "",
[Parameter(Mandatory = $false)]
[string]$ComputerName = "quic-server",
[Parameter(Mandatory = $false)]
[string]$WinRMUser = "",
[switch]$SkipRemote = $false
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
$ProgressPreference = 'SilentlyContinue'
if (!$IsWindows -and [string]::IsNullOrWhiteSpace($Remote)) {
$Remote = "quic-server"
}
# Remove any previous remote PowerShell sessions
Get-PSSession | Remove-PSSession
$Session = $null
if (!$SkipRemote) {
if ($Remote -eq "") {
if ($WinRMUser -ne "") {
$Session = New-PSSession -ComputerName $ComputerName -Credential $WinRMUser -ConfigurationName PowerShell.7
} else {
$Session = New-PSSession -ComputerName $ComputerName -ConfigurationName PowerShell.7
}
} else {
$Session = New-PSSession -HostName "$Remote"
}
}
if ($null -eq $Session) {
Write-Host "Failed to create remote session"
} else {
$RemoteAddress = $Session.ComputerName
Write-Output "Connected to: $RemoteAddress"
}
try {
if ($IsWindows) {
if ($null -ne (Get-Process -Name "secnetperf" -ErrorAction Ignore)) {
try {
Stop-Process -Name "secnetperf" -Force | Out-Null
}
catch {}
}
if ($null -ne (Get-Service -Name "secnetperfdrvpriv" -ErrorAction Ignore)) {
try {
net.exe stop secnetperfdrvpriv /y | Out-Null
}
catch {}
sc.exe delete secnetperfdrvpriv /y | Out-Null
}
if ($null -ne (Get-Service -Name "msquicpriv" -ErrorAction Ignore)) {
try {
net.exe stop msquicpriv /y | Out-Null
}
catch {}
sc.exe delete msquicpriv /y | Out-Null
}
if ($null -ne $Session) {
Invoke-Command -Session $Session -ScriptBlock {
if ($null -ne (Get-Process -Name "secnetperf" -ErrorAction Ignore)) {
try {
Stop-Process -Name "secnetperf" -Force | Out-Null
}
catch {}
}
if ($null -ne (Get-Service -Name "secnetperfdrvpriv" -ErrorAction Ignore)) {
try {
net.exe stop secnetperfdrvpriv /y | Out-Null
}
catch {}
sc.exe delete secnetperfdrvpriv /y | Out-Null
}
if ($null -ne (Get-Service -Name "msquicpriv" -ErrorAction Ignore)) {
try {
net.exe stop msquicpriv /y | Out-Null
}
catch {}
sc.exe delete msquicpriv /y | Out-Null
}
}
}
}
} finally {
if ($null -ne $Session) {
Remove-PSSession -Session $Session
}
}