title: netsh command output logging in powershell
body: <p>The below script works fine and displays all the iformation I need - however, there is a problem in displaying NETSH commands. So, normally in powershell if you enter the below:</p>
  
  <pre><code>netsh int tcp show global
  </code></pre>
  
  <p>It displays in the TABLe format as below:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>However, when I do this in a powershell script that logs to a LOG file the output is all scewed - ie the below:</p>
  
  <pre><code>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  
  </code></pre>
  
  <p>Any idea how I can keep the TABLE format that powershell command prompt displays?</p>
  
  <p>Script:</p>
  
  <pre><code> $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
  </code></pre>