From 52231254a509ed38b8e5f4db462e298a9b09854b Mon Sep 17 00:00:00 2001 From: ili101 Date: Sun, 7 Apr 2019 22:26:48 +0300 Subject: [PATCH] Replace " | Out-Null" with "$null = " everywhere just in case it degrades performance in other places --- ConvertExcelToImageFile.ps1 | 8 ++++---- ConvertToExcelXlsx.ps1 | 2 +- Export-Excel.ps1 | 6 +++--- Install.ps1 | 2 +- Send-SqlDataToExcel.ps1 | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ConvertExcelToImageFile.ps1 b/ConvertExcelToImageFile.ps1 index c89f069..08efd46 100644 --- a/ConvertExcelToImageFile.ps1 +++ b/ConvertExcelToImageFile.ps1 @@ -35,15 +35,15 @@ Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Opening Workbook and copying data" $xlWbk = $xlApp.Workbooks.Open($Path) $xlWbk.Worksheets($workSheetname).Select() - $xlWbk.ActiveSheet.Range($range).Select() | Out-Null - $xlApp.Selection.Copy() | Out-Null + $null = $xlWbk.ActiveSheet.Range($range).Select() + $null = $xlApp.Selection.Copy() Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Saving copied data" # Get-Clipboard came in with PS5. Older versions can use [System.Windows.Clipboard] but it is ugly. $image = Get-Clipboard -Format Image $image.Save($destination, $Format) Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Status "Closing Excel" - $xlWbk.ActiveSheet.Range("a1").Select() | Out-Null - $xlApp.Selection.Copy() | Out-Null + $null = $xlWbk.ActiveSheet.Range("a1").Select() + $null = $xlApp.Selection.Copy() $xlApp.Quit() Write-Progress -Activity "Exporting $range of $workSheetname in $Path" -Completed if ($show) {Start-Process -FilePath $destination} diff --git a/ConvertToExcelXlsx.ps1 b/ConvertToExcelXlsx.ps1 index 7d2eb6a..f280a4c 100644 --- a/ConvertToExcelXlsx.ps1 +++ b/ConvertToExcelXlsx.ps1 @@ -50,7 +50,7 @@ Function ConvertTo-ExcelXlsx { } $Excel.Visible = $false - $Excel.Workbooks.Open($xlsFile.FullName) | Out-Null + $null = $Excel.Workbooks.Open($xlsFile.FullName) $Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat) $Excel.ActiveWorkbook.Close() $Excel.Quit() diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index 7b819a9..f7f4072 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -1054,9 +1054,9 @@ } try { $TempZipPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.IO.Path]::GetRandomFileName()) - [io.compression.zipfile]::ExtractToDirectory($pkg.File, $TempZipPath) | Out-Null + $null = [io.compression.zipfile]::ExtractToDirectory($pkg.File, $TempZipPath) Remove-Item $pkg.File -Force - [io.compression.zipfile]::CreateFromDirectory($TempZipPath, $pkg.File) | Out-Null + $null = [io.compression.zipfile]::CreateFromDirectory($TempZipPath, $pkg.File) } catch {throw "Error resizipping $path : $_"} } @@ -1270,7 +1270,7 @@ Function Add-ExcelName { } else { Write-verbose -Message "Creating Named range '$RangeName' as $($Range.FullAddressAbsolute)." - $ws.Names.Add($RangeName, $Range) | Out-Null + $null = $ws.Names.Add($RangeName, $Range) } } catch {Write-Warning -Message "Failed adding named range '$RangeName' to worksheet '$($ws.Name)': $_" } diff --git a/Install.ps1 b/Install.ps1 index 66f7089..5d792c4 100644 --- a/Install.ps1 +++ b/Install.ps1 @@ -85,7 +85,7 @@ Process { } if (-not (Test-Path $InstallDirectory)) { - New-Item -Path $InstallDirectory -ItemType Directory -EA Stop | Out-Null + $null = New-Item -Path $InstallDirectory -ItemType Directory -EA Stop Write-Verbose "$ModuleName created module folder '$InstallDirectory'" } diff --git a/Send-SqlDataToExcel.ps1 b/Send-SqlDataToExcel.ps1 index 10ff9d6..066dfd6 100644 --- a/Send-SqlDataToExcel.ps1 +++ b/Send-SqlDataToExcel.ps1 @@ -59,7 +59,7 @@ C:\> $dbPath = 'C:\users\James\Documents\f1Results.xlsx' C:\> $SQL = "SELECT top 25 DriverName, Count(RaceDate) as Races, Count(Win) as Wins, Count(Pole) as Poles, Count(FastestLap) as Fastlaps " + " FROM Results GROUP BY DriverName ORDER BY (count(win)) DESC" - C:\> Get-SQL -Session F1 -excel -Connection $dbPath -sql $sql -OutputVariable Table | out-null + C:\> $null = Get-SQL -Session F1 -excel -Connection $dbPath -sql $sql -OutputVariable Table C:\> Send-SQLDataToExcel -DataTable $Table -Path ".\demo3.xlsx" -WorkSheetname Gpwinners -autosize -TableName winners -TableStyle Light6 -show