Сценарий, приведенный ниже, работает нормально и отображает всю необходимую информацию, однако при отображении команд NETSH возникает проблема.Так, обычно в powershell, если вы вводите следующее:
netsh int tcp show global
Отображается в формате TABLe, как показано ниже:
TCP Global Parameters
----------------------------------------------
Receive-Side Scaling State : disabled
Chimney Offload State : disabled
NetDMA State : enabled
Direct Cache Acess (DCA) : disabled
Receive Window Auto-Tuning Level : disabled
Add-On Congestion Control Provider : none
ECN Capability : disabled
RFC 1323 Timestamps : disabled
Однако, когда я делаю это в скрипте powershell, который регистрируетв файл LOG выводятся все данные, т.е. ниже:
Querying active state... TCP Global Parameters ---------------------------------------------- Receive-Side Scaling State : disabled Chimney Offload State : disabled NetDMA State : disabled Direct Cache Acess (DCA) : disabled Receive Window Auto-Tuning Level : disabled Add-On Congestion Control Provider : none ECN Capability : disabled RFC 1323 Timestamps : disabled
Есть идеи, как сохранить формат TABLE, отображаемый в командной строке powershell?
Сценарий:
$computerdel = gc env:computername
$t = "D:\temp\$(gc env:computername).log"
#$e = Test-Path $t rm $t -ErrorAction SilentlyContinue
#if ( $e -eq $true ) { rm $t }
#else { Write-Host "Shortcut does not exist." }
$Logfile = "D:\temp\$(gc env:computername).log"
Function LogWrite { Param ([string]$logstring)
Add-content $Logfile -value $logstring }
LogWrite
-----------------------------------------------------------------------------------------------------------------------------------------------
$Date = Get-Date
LogWrite "Script has been run on $Date - This is Servers Local Time"
LogWrite $computer = gc env:computername $onetcp = ((get-childitem
c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMajorPart).tostring()
$twotcp = ((get-childitem
c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMinorPart).tostring()
$threetcp = ((get-childitem
c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductBuildPart).tostring()
$fourtcp = ((get-childitem
c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductPrivatePart).tostring()
$onedfsr = ((get-childitem
c:\windows\system32\dfsrs.exe).Versioninfo.ProductMajorPart).tostring()
$twodfsr = ((get-childitem
c:\windows\system32\dfsrs.exe).Versioninfo.ProductMinorPart).tostring()
$threedfsr = ((get-childitem
c:\windows\system32\dfsrs.exe).Versioninfo.ProductBuildPart).tostring()
$fourdfsr = ((get-childitem
c:\windows\system32\dfsrs.exe).Versioninfo.ProductPrivatePart).tostring()
$hotfix1 = Get-HotFix -Id KB2450944 -ErrorAction SilentlyContinue
$hotfix2 = Get-HotFix -Id KB2582284 -ErrorAction SilentlyContinue
#$hotfix3 = Get-HotFix -Id KB979808 -ErrorAction SilentlyContinue
LogWrite
If ($hotfix2) { LogWrite "Hotfix KB2582284 is installed - This is
TCPIP.sys Upgrade Hotfix" -BackgroundColor Green -ForegroundColor
Black } else { LogWrite "Hotfix KB2582284 is NOT installed - Please
ensure you install this hotfix - This is DFSRS.exe Upgrade Hotfix"
-ForegroundColor "red" }
LogWrite "TCPIP.sys Version on $computer is:
""$onetcp.$twotcp.$threetcp.$fourtcp"" " LogWrite If ($hotfix1) {
LogWrite "Hotfix KB2450944 is installed - This is DFSRS.exe Upgrade
Hotfix" -BackgroundColor Green -ForegroundColor Black } else {
LogWrite "Hotfix KB2450944 is NOT installed - Please ensure you
install this hotfix - This is DFSRS.exe Upgrade Hotfix"
-ForegroundColor "red" } LogWrite "DFSRS.exe Version on $computer is: ""$onedfsr.$twodfsr.$threedfsr.$fourdfsr"" "
LogWrite
If (get-wmiobject win32_share | where-object {$_.Name -eq "REMINST"})
{ LogWrite "The REMINST share exists on $computer" } Else {
LogWrite "The REMINST share DOES NOT exist on $computer - Please
create as per standards" }
#If ($hotfix3) {
# LogWrite "Hotfix KB979808 is installed" -BackgroundColor Green -ForegroundColor Black
# }
#else {
# LogWrite "Hotfix KB979808 is NOT installed - Please ensure you install this hotfix" -ForegroundColor "red"
#} LogWrite
$u = "DBG\ADS-ALL-ROFS-Manager"; net localgroup "Distributed COM
Users" | Where {$_ -match $u}
If ($u) { LogWrite "DBG\ADS-ALL-ROFS-Manager is part of Distributed
COM Users localgroup on $computer" } else { LogWrite
"DBG\ADS-ALL-ROFS-Manager is NOT part of Distributed COM Users
localgroup on $computer" } LogWrite $disabletaskoffload =
Get-ItemProperty
'HKLM:\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters' -Name
'DisableTaskOffload' | fl DisableTaskOffload -ErrorAction
SilentlyContinue $EnableTCPChimney = Get-ItemProperty
'HKLM:\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters' -Name
'EnableTCPChimney' | fl EnableTCPChimney $EnableTCPA =
Get-ItemProperty
'HKLM:\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters' -Name
'EnableTCPA' | fl EnableTCPA $EnableRSS = Get-ItemProperty
'HKLM:\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters' -Name
'EnableRSS' | fl EnableRSS
If ($disabletaskoffload) { LogWrite "Registry Key DisableTaskOffload
is set" -BackgroundColor Green -ForegroundColor Black } else {
LogWrite "Registry Key DisableTaskOffload is NOT set"
-ForegroundColor "red" } If ($EnableTCPChimney) { LogWrite "Registry Key EnableTCPChimney is set" -BackgroundColor Green
-ForegroundColor Black } else { LogWrite "Registry Key EnableTCPChimney is NOT set" -ForegroundColor "red" } If
($EnableTCPA) { LogWrite "Registry Key EnableTCPA is set"
-BackgroundColor Green -ForegroundColor Black } else { LogWrite "Registry Key EnableTCPA is NOT set" -ForegroundColor "red" } If
($EnableRSS) { LogWrite "Registry Key EnableRSS is set"
-BackgroundColor Green -ForegroundColor Black } else { LogWrite "Registry Key EnableRSS is NOT set" -ForegroundColor "red" } $netsh =
netsh int tcp show global LogWrite LogWrite "***Running Netsh
Check***" LogWrite "Ensure the following are set to disabled:"
LogWrite "Receive-Side Scaling State: Disabled" LogWrite "Chimney
Offload State: Disabled" LogWrite "Receive Window Auto-Tuning Level:
Disabled" LogWrite LogWrite $netsh LogWrite