1. 程式人生 > >windows powershell指令碼--------針對SR-IOV網絡卡修改receivebuffer和transmitbuffer

windows powershell指令碼--------針對SR-IOV網絡卡修改receivebuffer和transmitbuffer

function Get-RegistryValue($key, $value) { 
    (Get-ItemProperty -Path $key -Name $value).$value 
}




function Set-RegistryValue($key, $name, $value) { 
    Set-ItemProperty $key $name $value 
}




function Set-Buffer($INDEXS) {
foreach($INDEX in $INDEXS) {
$REGIS_PATH=$HOME_PATH + "\" + "00" + "$INDEX"
try {
$RECE_VALUE=Get-RegistryValue $REGIS_PATH  "*ReceiveBuffers"
$TRAN_VALUE=Get-RegistryValue $REGIS_PATH  "*TransmitBuffers"
}
catch {
$RECE_VALUE=0
$TRAN_VALUE=0
}

if($RECE_VALUE -ne $BUFFER_VALUE) {
Set-RegistryValue $REGIS_PATH "*ReceiveBuffers" $BUFFER_VALUE
}

if($TRAN_VALUE -ne $BUFFER_VALUE) {
Set-RegistryValue $REGIS_PATH "*TransmitBuffers" $BUFFER_VALUE
}
}
}
 
 
try {
$INDEXS=Get-WmiObject win32_networkadapterconfiguration | 
where {$_.IPEnabled -and $_.DHCPEnabled -and $_.ServiceName -eq "v1q"} | 
Select-Object -ExpandProperty Index
}
catch {
$INDEXS=0
}




$HKLM_PATH="HKLM:\SYSTEM\CurrentControlSet\Control\"
$HOME_PATH= $HKLM_PATH +"Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"




$BUFFER_VALUE=4096


if($INDEXS) {
Set-Buffer($INDEXS)
}