Created
February 3, 2015 17:42
-
-
Save takekazuomi/e90587dbdfb397a049d0 to your computer and use it in GitHub Desktop.
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
# TCP tune for TCP/IP port exhaustion. | |
# | |
# check current port range | |
# netsh int ipv4 show dynamicportrange tcp | |
# | |
function SetPropertyDWORD([string]$path, [string]$key, [string]$Value) { | |
$oldValue = "0x{0:X}" -f (Get-ItemProperty -path $path).$key | |
if($Value -eq $oldValue) | |
{ | |
return $false; | |
} | |
Set-ItemProperty -path $path -name $key -Type DWORD -Value $Value | |
$newValue = (Get-ItemProperty -path $path).$key | |
$data = "$path\$key=$oldValue" | |
Write-Output "Value for $path\$key changed from $oldValue to $newValue" | |
return $true | |
} | |
$path = "HKLM:\System\CurrentControlSet\Services\Tcpip\Parameters" | |
$updated = SetPropertyDWORD $path "TcpTimedWaitDelay" 0x1e | |
if($updated) | |
{ | |
netsh int ipv4 set dynamicport tcp start=1025 num=64506 | |
netsh int ipv4 show dynamicportrange tcp | |
Write-Host -Object $(Get-Date), "reboot" | |
Restart-Computer | |
} | |
else | |
{ | |
netsh int ipv4 show dynamicportrange tcp | |
Write-Host -Object $(Get-Date), "no reboot" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment