From 5e87c3f6a776d1a43b528ac21d0bc918b9bfc861 Mon Sep 17 00:00:00 2001 From: jhoneill Date: Mon, 25 Nov 2019 23:40:51 +0000 Subject: [PATCH] fixes to casing, and some basic functions changed to advanced --- ArgumentCompletion.ps1 | 4 +- CI/Test-SingleFunctions.ps1 | 48 +++++++++++-------- Examples/CustomizeExportExcel/Out-Excel.ps1 | 2 +- Examples/Index - Music.ps1 | 2 +- Export-charts.ps1 | 2 +- .../Add-ConditionalFormatting.ps1 | 6 +-- ExportedCommands/Add-ExcelChart.ps1 | 2 +- .../Add-ExcelDataValidationRule.ps1 | 4 +- ExportedCommands/Add-PivotTable.ps1 | 2 +- ExportedCommands/Close-ExcelPackage.ps1 | 7 ++- ExportedCommands/Compare-Worksheet.ps1 | 10 ++-- .../Convert-ExcelRangeToImage.ps1 | 4 +- ExportedCommands/ConvertTo-ExcelXlsx.ps1 | 6 +-- ExportedCommands/Expand-NumberFormat.ps1 | 33 +------------ ExportedCommands/Export-Excel.ps1 | 2 +- ExportedCommands/Export-ExcelSheet.ps1 | 1 - .../Export-MultipleExcelSheets.ps1 | 1 - ExportedCommands/Get-ExcelSheetInfo.ps1 | 2 +- ExportedCommands/Get-ExcelWorkbookInfo.ps1 | 10 ++-- ExportedCommands/Get-Range.ps1 | 4 +- ExportedCommands/Get-XYRange.ps1 | 1 + ExportedCommands/Import-Excel.ps1 | 8 ++-- ExportedCommands/Import-UPS.ps1 | 1 + ExportedCommands/Import-USPS.ps1 | 2 +- ExportedCommands/Invoke-Sum.ps1 | 1 + ExportedCommands/Merge-MultipleSheets.ps1 | 2 +- ExportedCommands/Merge-Worksheet.ps1 | 10 ++-- ExportedCommands/New-ConditionalText.ps1 | 2 +- ExportedCommands/New-ExcelChartDefinition.ps1 | 2 +- ExportedCommands/New-ExcelStyle.ps1 | 2 +- ExportedCommands/New-PSItem.ps1 | 2 +- ExportedCommands/Open-ExcelPackage.ps1 | 4 +- ExportedCommands/Remove-Worksheet.ps1 | 4 +- ExportedCommands/Send-SQLDataToExcel.ps1 | 2 +- ExportedCommands/Set-CellStyle.ps1 | 1 + ExportedCommands/Set-ExcelColumn.ps1 | 8 ++-- ExportedCommands/Set-ExcelRange.ps1 | 4 +- ExportedCommands/Set-ExcelRow.ps1 | 8 ++-- ExportedCommands/Set-WorksheetProtection.ps1 | 6 +-- .../Update-FirstObjectProperties.ps1 | 9 ++-- GetExcelTable.ps1 | 8 ++-- ImportExcel.psm1 | 6 +-- Install.ps1 | 6 +-- 43 files changed, 118 insertions(+), 133 deletions(-) diff --git a/ArgumentCompletion.ps1 b/ArgumentCompletion.ps1 index b0268da..f7ced45 100644 --- a/ArgumentCompletion.ps1 +++ b/ArgumentCompletion.ps1 @@ -6,7 +6,7 @@ } function ListFonts { - [cmdletbinding()] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingEmptyCatchBlock", "")] param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) if (-not $script:FontFamilies) { @@ -77,7 +77,7 @@ function WorksheetArgumentCompleter { } } -If (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { +if (Get-Command -ErrorAction SilentlyContinue -name Register-ArgumentCompleter) { Register-ArgumentCompleter -CommandName Export-Excel -ParameterName TitleBackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName BackgroundColor -ScriptBlock $Function:ColorCompletion Register-ArgumentCompleter -CommandName Add-ConditionalFormatting -ParameterName DataBarColor -ScriptBlock $Function:ColorCompletion diff --git a/CI/Test-SingleFunctions.ps1 b/CI/Test-SingleFunctions.ps1 index c8622cd..6c2350b 100644 --- a/CI/Test-SingleFunctions.ps1 +++ b/CI/Test-SingleFunctions.ps1 @@ -1,15 +1,14 @@  -Function Test-SingleFunction { +function Test-SingleFunction { param ( [parameter(ValueFromPipeline=$true)] - $path ) + $path ) begin { - Push-Location "C:\Users\mcp\Documents\GitHub\ImportExcel" - $exportedFunctions = (Import-LocalizedData -FileName "ImportExcel.psd1").functionsToExport - Pop-Location + $psd = Get-Content -Raw "$PSScriptRoot\..\ImportExcel.psd1" + $exportedFunctions = (Invoke-Command ([scriptblock]::Create($psd))).functionsToExport $reg = [Regex]::new(@" - function\s*[-\w]+\s*{ # The function name and opening '{' - (?: + function\s*[-\w]+\s*{ # The function name and opening '{' + (?: [^{}]+ # Match all non-braces | (? { ) # Match '{', and capture into 'open' @@ -18,27 +17,38 @@ Function Test-SingleFunction { )* (?(open)(?!)) # Fails if 'open' stack isn't empty } # Functions closing '}' -"@, 33) # 33 = ignore case and white space. - - - }# +"@, 57) # 41 = compile ignore case and white space. +$reg2 = [Regex]::new(@" + ^function\s*[-\w]+\s*{ # The function name and opening '{' + ( + \#.*?[\r\n]+ # single line comment + | # or + \s*<\#.*?\#> # <#comment block#> + | # or + \s*\[.*?\] # [attribute tags] + )* +"@, 57) +# 43 = compile, multi-line, ignore case and white space. + } process { $item = Get-item $Path $name = $item.Name -replace "\.\w+$","" Write-Verbose $name $file = Get-Content $item -Raw - $m = $reg.Matches($file) - - - #based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis + $m = $reg.Matches($file) + + #based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis if ($m.Count -eq 0) {return "Could not find $name function in $($item.name)"} elseif ($m.Count -ge 2) {return "Multiple functions in $($item.name)"} elseif ($exportedFunctions -cnotcontains $name) {return "$name not exported (or in the wrong case)"} - elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"} - elseif ($m[0] -inotmatch "^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param") {return "No param block in $name"} - elseif ($m[0] -inotmatch "\[cmdletbinding\(" -and + elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"} + $m2 = [regex]::Match($m[0],"param",[System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + if (-not $m2.Success) {return "No param block in $name"} + # elseif ($m[0] -inotmatch "(?s)^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param") + # elseif ($reg2.IsMatch($m[0].Value)) {return "function $name has comment-based help"} + elseif ($m[0] -inotmatch "\[CmdletBinding\(" -and $m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"} elseif (-not (& $Name -?).synopsis) {return "$name has no help"} - else {return "$name OK"} + else {Write-Verbose "$name OK"} } } \ No newline at end of file diff --git a/Examples/CustomizeExportExcel/Out-Excel.ps1 b/Examples/CustomizeExportExcel/Out-Excel.ps1 index b320241..0845d24 100644 --- a/Examples/CustomizeExportExcel/Out-Excel.ps1 +++ b/Examples/CustomizeExportExcel/Out-Excel.ps1 @@ -10,7 +10,7 @@ Preset2 will set AutoFilter and add the Title "Daily Report". (see comments and code below). #> -Function Out-Excel { +function Out-Excel { [CmdletBinding(DefaultParameterSetName = 'Default')] param( [switch] diff --git a/Examples/Index - Music.ps1 b/Examples/Index - Music.ps1 index d518495..f895505 100644 --- a/Examples/Index - Music.ps1 +++ b/Examples/Index - Music.ps1 @@ -1,5 +1,5 @@ #requires -modules "Get-IndexedItem" -[cmdletbinding()] +[CmdletBinding()] Param() Remove-Item ~\documents\music.xlsx -ErrorAction SilentlyContinue [System.Diagnostics.Stopwatch]$stopwatch = [System.Diagnostics.Stopwatch]::StartNew() diff --git a/Export-charts.ps1 b/Export-charts.ps1 index d78a9a6..96c6496 100644 --- a/Export-charts.ps1 +++ b/Export-charts.ps1 @@ -10,7 +10,7 @@ Exports the charts to PNG files in MyDocuments , and returns file objects representing the newly created files #> -Param ( +param( #Path to the Excel file whose chars we will export. $Path = "C:\Users\public\Documents\stats.xlsx", #If specified, output file objects representing the image files diff --git a/ExportedCommands/Add-ConditionalFormatting.ps1 b/ExportedCommands/Add-ConditionalFormatting.ps1 index 92ce94b..dffa8d1 100644 --- a/ExportedCommands/Add-ConditionalFormatting.ps1 +++ b/ExportedCommands/Add-ConditionalFormatting.ps1 @@ -1,5 +1,5 @@ -Function Add-ConditionalFormatting { - Param ( +function Add-ConditionalFormatting { + param ( [Parameter(Mandatory = $true, Position = 0)] [Alias("Range")] $Address , @@ -50,7 +50,7 @@ ) #Allow conditional formatting to work like Set-ExcelRange (with single ADDRESS parameter), split it to get worksheet and range of cells. - If ($Address -is [OfficeOpenXml.Table.ExcelTable]) { + if ($Address -is [OfficeOpenXml.Table.ExcelTable]) { $Worksheet = $Address.Address.Worksheet $Address = $Address.Address.Address } diff --git a/ExportedCommands/Add-ExcelChart.ps1 b/ExportedCommands/Add-ExcelChart.ps1 index 1fbaf62..88a0d46 100644 --- a/ExportedCommands/Add-ExcelChart.ps1 +++ b/ExportedCommands/Add-ExcelChart.ps1 @@ -1,6 +1,6 @@ function Add-ExcelChart { - [cmdletbinding(DefaultParameterSetName = 'Worksheet')] + [CmdletBinding(DefaultParameterSetName = 'Worksheet')] [OutputType([OfficeOpenXml.Drawing.Chart.ExcelChart])] param( [Parameter(ParameterSetName = 'Worksheet', Mandatory = $true)] diff --git a/ExportedCommands/Add-ExcelDataValidationRule.ps1 b/ExportedCommands/Add-ExcelDataValidationRule.ps1 index 6658ca3..cd3f732 100644 --- a/ExportedCommands/Add-ExcelDataValidationRule.ps1 +++ b/ExportedCommands/Add-ExcelDataValidationRule.ps1 @@ -1,6 +1,6 @@ -Function Add-ExcelDataValidationRule { +function Add-ExcelDataValidationRule { [CmdletBinding()] - Param( + param( [Parameter(ValueFromPipeline = $true,Position=0)] [Alias("Address")] $Range , diff --git a/ExportedCommands/Add-PivotTable.ps1 b/ExportedCommands/Add-PivotTable.ps1 index 589870a..5a7fadb 100644 --- a/ExportedCommands/Add-PivotTable.ps1 +++ b/ExportedCommands/Add-PivotTable.ps1 @@ -1,5 +1,5 @@ function Add-PivotTable { - [cmdletbinding(defaultParameterSetName = 'ChartbyParams')] + [CmdletBinding(defaultParameterSetName = 'ChartbyParams')] [OutputType([OfficeOpenXml.Table.PivotTable.ExcelPivotTable])] param ( [Parameter(Mandatory = $true)] diff --git a/ExportedCommands/Close-ExcelPackage.ps1 b/ExportedCommands/Close-ExcelPackage.ps1 index d49425e..c2d9ad4 100644 --- a/ExportedCommands/Close-ExcelPackage.ps1 +++ b/ExportedCommands/Close-ExcelPackage.ps1 @@ -1,8 +1,7 @@ - -Function Close-ExcelPackage { +function Close-ExcelPackage { [CmdLetBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] - Param ( + param ( [parameter(Mandatory=$true, ValueFromPipeline=$true)] [OfficeOpenXml.ExcelPackage]$ExcelPackage, [switch]$Show, @@ -16,7 +15,7 @@ Function Close-ExcelPackage { else { if ($Calculate) { try { [OfficeOpenXml.CalculationExtension]::Calculate($ExcelPackage.Workbook) } - Catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."} + catch { Write-Warning "One or more errors occured while calculating, save will continue, but there may be errors in the workbook."} } if ($SaveAs) { $SaveAs = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($SaveAs) diff --git a/ExportedCommands/Compare-Worksheet.ps1 b/ExportedCommands/Compare-Worksheet.ps1 index 2f23ffb..05aa23a 100644 --- a/ExportedCommands/Compare-Worksheet.ps1 +++ b/ExportedCommands/Compare-Worksheet.ps1 @@ -1,8 +1,8 @@ -Function Compare-Worksheet { - [cmdletbinding(DefaultParameterSetName)] +function Compare-Worksheet { + [CmdletBinding(DefaultParameterSetName)] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] - Param( + param( [parameter(Mandatory=$true,Position=0)] $Referencefile , [parameter(Mandatory=$true,Position=1)] @@ -29,7 +29,7 @@ #if the filenames don't resolve, give up now. try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} - Catch { Write-Warning -Message "Could not Resolve the filenames." ; return } + catch { Write-Warning -Message "Could not Resolve the filenames." ; return } #If we have one file , we must have two different worksheet names. If we have two files we can have a single string or two strings. if ($onefile -and ( ($WorkSheetName.count -ne 2) -or $WorkSheetName[0] -eq $WorkSheetName[1] ) ) { @@ -46,7 +46,7 @@ $sheet1 = Import-Excel -Path $Referencefile -WorksheetName $WorkSheet1 @params $sheet2 = Import-Excel -Path $Differencefile -WorksheetName $WorkSheet2 @Params } - Catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return } + catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return } #Get Column headings and create a hash table of Name to column letter. $headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using Get-member would sort them alphabetically! diff --git a/ExportedCommands/Convert-ExcelRangeToImage.ps1 b/ExportedCommands/Convert-ExcelRangeToImage.ps1 index 1569201..69a4c85 100644 --- a/ExportedCommands/Convert-ExcelRangeToImage.ps1 +++ b/ExportedCommands/Convert-ExcelRangeToImage.ps1 @@ -1,6 +1,6 @@ -Function Convert-ExcelRangeToImage { +function Convert-ExcelRangeToImage { [alias("Convert-XlRangeToImage")] - Param ( + param ( [parameter(Mandatory=$true)] $Path, $workSheetname = "Sheet1" , diff --git a/ExportedCommands/ConvertTo-ExcelXlsx.ps1 b/ExportedCommands/ConvertTo-ExcelXlsx.ps1 index 21ef2f3..36c67c4 100644 --- a/ExportedCommands/ConvertTo-ExcelXlsx.ps1 +++ b/ExportedCommands/ConvertTo-ExcelXlsx.ps1 @@ -1,13 +1,13 @@ -Function ConvertTo-ExcelXlsx { +function ConvertTo-ExcelXlsx { [CmdletBinding()] - Param + param ( [parameter(Mandatory = $true, ValueFromPipeline)] [string]$Path, [parameter(Mandatory = $false)] [switch]$Force ) - Process { + process { if (-Not ($Path | Test-Path) ) { throw "File not found" } diff --git a/ExportedCommands/Expand-NumberFormat.ps1 b/ExportedCommands/Expand-NumberFormat.ps1 index cbefdbb..650a1b6 100644 --- a/ExportedCommands/Expand-NumberFormat.ps1 +++ b/ExportedCommands/Expand-NumberFormat.ps1 @@ -1,34 +1,5 @@ - -function Expand-NumberFormat { - <# - .SYNOPSIS - Converts short names for number formats to the formatting strings used in Excel - .DESCRIPTION - Where you can type a number format you can write, for example, 'Short-Date' - and the module will translate it into the format string used by Excel. - Some formats, like Short-Date change how they are presented when Excel - loads (so date will use the local ordering of year, month and Day). Other - formats change how they appear when loaded with different cultures - (depending on the country "," or "." or " " may be the thousand seperator - although Excel always stores it as ",") - .EXAMPLE - Expand-NumberFormat percentage - - Returns "0.00%" - .EXAMPLE - Expand-NumberFormat Currency - - Returns the currency format specified in the local regional settings. This - may not be the same as Excel uses. The regional settings set the currency - symbol and then whether it is before or after the number and separated with - a space or not; for negative numbers the number may be wrapped in parentheses - or a - sign might appear before or after the number and symbol. - So this returns $#,##0.00;($#,##0.00) for English US, #,##0.00 €;€#,##0.00- - for French. (Note some Eurozone countries write €1,23 and others 1,23€ ) - In French the decimal point will be rendered as a "," and the thousand - separator as a space. - #> - [cmdletbinding()] +function Expand-NumberFormat { + [CmdletBinding()] [OutputType([String])] param ( #the format string to Expand diff --git a/ExportedCommands/Export-Excel.ps1 b/ExportedCommands/Export-Excel.ps1 index 1024d41..09fc486 100644 --- a/ExportedCommands/Export-Excel.ps1 +++ b/ExportedCommands/Export-Excel.ps1 @@ -403,7 +403,7 @@ Write-Warning -Message "AutoNameRange: Property name '$targetRangeName' is also a valid Excel address and may cause issues. Consider renaming the property." } } - Catch { + catch { Write-Warning -Message "AutoNameRange: Testing '$targetRangeName' caused an error. This should be harmless, but a change of property name may be needed.." } } diff --git a/ExportedCommands/Export-ExcelSheet.ps1 b/ExportedCommands/Export-ExcelSheet.ps1 index b703d0f..27e8de5 100644 --- a/ExportedCommands/Export-ExcelSheet.ps1 +++ b/ExportedCommands/Export-ExcelSheet.ps1 @@ -1,5 +1,4 @@ function Export-ExcelSheet { - [CmdletBinding()] param ( diff --git a/ExportedCommands/Export-MultipleExcelSheets.ps1 b/ExportedCommands/Export-MultipleExcelSheets.ps1 index d8012e2..80ce9f9 100644 --- a/ExportedCommands/Export-MultipleExcelSheets.ps1 +++ b/ExportedCommands/Export-MultipleExcelSheets.ps1 @@ -1,7 +1,6 @@ function Export-MultipleExcelSheets { [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")] - param( [Parameter(Mandatory = $true)] $Path, diff --git a/ExportedCommands/Get-ExcelSheetInfo.ps1 b/ExportedCommands/Get-ExcelSheetInfo.ps1 index f4fb88a..f5c6cf3 100644 --- a/ExportedCommands/Get-ExcelSheetInfo.ps1 +++ b/ExportedCommands/Get-ExcelSheetInfo.ps1 @@ -1,4 +1,4 @@ -Function Get-ExcelSheetInfo { +function Get-ExcelSheetInfo { [CmdletBinding()] param( [Alias('FullName')] diff --git a/ExportedCommands/Get-ExcelWorkbookInfo.ps1 b/ExportedCommands/Get-ExcelWorkbookInfo.ps1 index a064314..515cce4 100644 --- a/ExportedCommands/Get-ExcelWorkbookInfo.ps1 +++ b/ExportedCommands/Get-ExcelWorkbookInfo.ps1 @@ -1,13 +1,13 @@ -Function Get-ExcelWorkbookInfo { +function Get-ExcelWorkbookInfo { [CmdletBinding()] - Param ( + param ( [Alias('FullName')] [Parameter(ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, Mandatory=$true)] [String]$Path ) - Process { - Try { + process { + try { $Path = (Resolve-Path $Path).ProviderPath $stream = New-Object -TypeName System.IO.FileStream -ArgumentList $Path,'Open','Read','ReadWrite' @@ -20,7 +20,7 @@ $xl.Dispose() $xl = $null } - Catch { + catch { throw "Failed retrieving Excel workbook information for '$Path': $_" } } diff --git a/ExportedCommands/Get-Range.ps1 b/ExportedCommands/Get-Range.ps1 index e25db9c..d127afb 100644 --- a/ExportedCommands/Get-Range.ps1 +++ b/ExportedCommands/Get-Range.ps1 @@ -1,3 +1,5 @@ -function Get-Range ($start=0,$stop,$step=1) { +function Get-Range { + [CmdletBinding()] + param($start=0,$stop,$step=1) for ($idx = $start; $idx -lt $stop; $idx+=$step) {$idx} } \ No newline at end of file diff --git a/ExportedCommands/Get-XYRange.ps1 b/ExportedCommands/Get-XYRange.ps1 index f28c8c8..734d263 100644 --- a/ExportedCommands/Get-XYRange.ps1 +++ b/ExportedCommands/Get-XYRange.ps1 @@ -1,4 +1,5 @@ function Get-XYRange { + [CmdletBinding()] param($targetData) $record = $targetData | Select-Object -First 1 diff --git a/ExportedCommands/Import-Excel.ps1 b/ExportedCommands/Import-Excel.ps1 index 94ec48f..5bd4389 100644 --- a/ExportedCommands/Import-Excel.ps1 +++ b/ExportedCommands/Import-Excel.ps1 @@ -47,20 +47,20 @@ else { $Paths = '' } - Function Get-PropertyNames { + function Get-PropertyNames { <# .SYNOPSIS Create objects containing the column number and the column name for each of the different header types. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = "Name would be incorrect, and command is not exported")] - Param ( + param( [Parameter(Mandatory)] [Int[]]$Columns, [Parameter(Mandatory)] [Int]$StartRow ) - Try { + try { if ($HeaderName) { $i = 0 foreach ($H in $HeaderName) { @@ -86,7 +86,7 @@ } } } - Catch { + catch { throw "Failed creating property names: $_" ; return } } diff --git a/ExportedCommands/Import-UPS.ps1 b/ExportedCommands/Import-UPS.ps1 index f1ad15f..16d2636 100644 --- a/ExportedCommands/Import-UPS.ps1 +++ b/ExportedCommands/Import-UPS.ps1 @@ -1,4 +1,5 @@ function Import-UPS { + [CmdletBinding()] param( $TrackingNumber, [Switch]$UseDefaultCredentials diff --git a/ExportedCommands/Import-USPS.ps1 b/ExportedCommands/Import-USPS.ps1 index e45ed38..fcb8ad1 100644 --- a/ExportedCommands/Import-USPS.ps1 +++ b/ExportedCommands/Import-USPS.ps1 @@ -1,5 +1,5 @@ function Import-USPS { - + [CmdletBinding()] param( $TrackingNumber, [Switch]$UseDefaultCredentials diff --git a/ExportedCommands/Invoke-Sum.ps1 b/ExportedCommands/Invoke-Sum.ps1 index 7343098..8f6a3f3 100644 --- a/ExportedCommands/Invoke-Sum.ps1 +++ b/ExportedCommands/Invoke-Sum.ps1 @@ -1,4 +1,5 @@ function Invoke-Sum { + [CmdletBinding()] param( $data, $dimension, diff --git a/ExportedCommands/Merge-MultipleSheets.ps1 b/ExportedCommands/Merge-MultipleSheets.ps1 index 14017dc..996bdf4 100644 --- a/ExportedCommands/Merge-MultipleSheets.ps1 +++ b/ExportedCommands/Merge-MultipleSheets.ps1 @@ -1,5 +1,5 @@ function Merge-MultipleSheets { - [cmdletbinding()] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")] #[Alias("Merge-MulipleSheets")] #There was a spelling error in the first release. This was there to ensure things didn't break but intelisense gave the alias first. diff --git a/ExportedCommands/Merge-Worksheet.ps1 b/ExportedCommands/Merge-Worksheet.ps1 index 36c0e88..8a561a1 100644 --- a/ExportedCommands/Merge-Worksheet.ps1 +++ b/ExportedCommands/Merge-Worksheet.ps1 @@ -1,6 +1,6 @@ function Merge-Worksheet { - [cmdletbinding(SupportsShouldProcess=$true)] - Param( + [CmdletBinding(SupportsShouldProcess=$true)] + param( [parameter(ParameterSetName='A',Mandatory=$true,Position=0)] #A = Compare two files default headers [parameter(ParameterSetName='B',Mandatory=$true,Position=0)] #B = Compare two files user supplied headers [parameter(ParameterSetName='C',Mandatory=$true,Position=0)] #C = Compare two files headers P1, P2, P3 etc @@ -76,7 +76,7 @@ if ($Referencefile -and $Differencefile) { #if the filenames don't resolve, give up now. try { $oneFile = ((Resolve-Path -Path $Referencefile -ErrorAction Stop).path -eq (Resolve-Path -Path $Differencefile -ErrorAction Stop).path)} - Catch { Write-Warning -Message "Could not Resolve the filenames." ; return } + catch { Write-Warning -Message "Could not Resolve the filenames." ; return } #If we have one file , we must have two different Worksheet names. If we have two files $WorksheetName can be a single string or two strings. if ($onefile -and ( ($WorksheetName.count -ne 2) -or $WorksheetName[0] -eq $WorksheetName[1] ) ) { @@ -94,7 +94,7 @@ $ReferenceObject = Import-Excel -Path $Referencefile -WorksheetName $Worksheet1 @params $DifferenceObject = Import-Excel -Path $Differencefile -WorksheetName $Worksheet2 @Params } - Catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return } + catch {Write-Warning -Message "Could not read the Worksheet from $Referencefile::$Worksheet1 and/or $Differencefile::$Worksheet2." ; return } if ($NoHeader) {$firstDataRow = $Startrow } else {$firstDataRow = $Startrow + 1} } elseif ( $Differencefile) { @@ -102,7 +102,7 @@ $params = @{WorksheetName=$WorksheetName; Path=$Differencefile; ErrorAction=[System.Management.Automation.ActionPreference]::Stop } foreach ($p in @("HeaderName","NoHeader","StartRow")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}} try {$DifferenceObject = Import-Excel @Params } - Catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return } + catch {Write-Warning -Message "Could not read the Worksheet '$WorksheetName' from $Differencefile::$WorksheetName." ; return } if ($DiffPrefix -eq "=>" ) { $DiffPrefix = (Split-Path -Path $Differencefile -Leaf) -replace "\.xlsx$","" } diff --git a/ExportedCommands/New-ConditionalText.ps1 b/ExportedCommands/New-ConditionalText.ps1 index a5b6743..e7e990c 100644 --- a/ExportedCommands/New-ConditionalText.ps1 +++ b/ExportedCommands/New-ConditionalText.ps1 @@ -1,5 +1,5 @@ function New-ConditionalText { - [cmdletbinding()] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system State')] param( #[Parameter(Mandatory=$true)] diff --git a/ExportedCommands/New-ExcelChartDefinition.ps1 b/ExportedCommands/New-ExcelChartDefinition.ps1 index e657d84..f024b9b 100644 --- a/ExportedCommands/New-ExcelChartDefinition.ps1 +++ b/ExportedCommands/New-ExcelChartDefinition.ps1 @@ -1,6 +1,6 @@ function New-ExcelChartDefinition { [Alias("New-ExcelChart")] #This was the former name. The new name reflects that we are defining a chart, not making one in the workbook. - [cmdletbinding()] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] param( $Title = "Chart Title", diff --git a/ExportedCommands/New-ExcelStyle.ps1 b/ExportedCommands/New-ExcelStyle.ps1 index a88d122..2bb2cde 100644 --- a/ExportedCommands/New-ExcelStyle.ps1 +++ b/ExportedCommands/New-ExcelStyle.ps1 @@ -1,5 +1,5 @@ function New-ExcelStyle { - [cmdletbinding()] + [CmdletBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Does not change system State')] param ( [Alias("Address")] diff --git a/ExportedCommands/New-PSItem.ps1 b/ExportedCommands/New-PSItem.ps1 index 4e10276..7dd2653 100644 --- a/ExportedCommands/New-PSItem.ps1 +++ b/ExportedCommands/New-PSItem.ps1 @@ -1,7 +1,7 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function', Target='New*', Justification='Does not change system State')] param() function New-PSItem { - + param() $totalArgs = $args.Count if($args[-1] -is [array]) { diff --git a/ExportedCommands/Open-ExcelPackage.ps1 b/ExportedCommands/Open-ExcelPackage.ps1 index 4277ba5..a645e07 100644 --- a/ExportedCommands/Open-ExcelPackage.ps1 +++ b/ExportedCommands/Open-ExcelPackage.ps1 @@ -1,8 +1,8 @@ -Function Open-ExcelPackage { +function Open-ExcelPackage { [CmdLetBinding()] [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword","")] [OutputType([OfficeOpenXml.ExcelPackage])] - Param ( + param( #The path to the file to open. [Parameter(Mandatory=$true)]$Path, #If specified, any running instances of Excel will be terminated before opening the file. diff --git a/ExportedCommands/Remove-Worksheet.ps1 b/ExportedCommands/Remove-Worksheet.ps1 index a2bbb93..e8d0d8f 100644 --- a/ExportedCommands/Remove-Worksheet.ps1 +++ b/ExportedCommands/Remove-Worksheet.ps1 @@ -1,5 +1,5 @@ -Function Remove-Worksheet { - [cmdletbinding(SupportsShouldProcess=$true)] +function Remove-Worksheet { + [CmdletBinding(SupportsShouldProcess=$true)] param( # [Parameter(ValueFromPipelineByPropertyName)] [Parameter(ValueFromPipelineByPropertyName)] diff --git a/ExportedCommands/Send-SQLDataToExcel.ps1 b/ExportedCommands/Send-SQLDataToExcel.ps1 index 0ba3169..bdf6d3c 100644 --- a/ExportedCommands/Send-SQLDataToExcel.ps1 +++ b/ExportedCommands/Send-SQLDataToExcel.ps1 @@ -1,4 +1,4 @@ -Function Send-SQLDataToExcel { +function Send-SQLDataToExcel { [CmdletBinding(DefaultParameterSetName="none")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification="Allowed to use DBSessions Global variable from GETSQL Module")] diff --git a/ExportedCommands/Set-CellStyle.ps1 b/ExportedCommands/Set-CellStyle.ps1 index 96ca249..02a48b0 100644 --- a/ExportedCommands/Set-CellStyle.ps1 +++ b/ExportedCommands/Set-CellStyle.ps1 @@ -2,6 +2,7 @@ param() function Set-CellStyle { + [CmdletBinding()] param( $Worksheet, $Row, diff --git a/ExportedCommands/Set-ExcelColumn.ps1 b/ExportedCommands/Set-ExcelColumn.ps1 index 6cc51e5..feb9d4e 100644 --- a/ExportedCommands/Set-ExcelColumn.ps1 +++ b/ExportedCommands/Set-ExcelColumn.ps1 @@ -1,10 +1,10 @@ -Function Set-ExcelColumn { - [cmdletbinding()] +function Set-ExcelColumn { + [CmdletBinding()] [Alias("Set-Column")] [OutputType([OfficeOpenXml.ExcelColumn],[String])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] - Param ( + param( [Parameter(ParameterSetName="Package",Mandatory=$true)] [OfficeOpenXml.ExcelPackage]$ExcelPackage, [Parameter(ParameterSetName="Package")] diff --git a/ExportedCommands/Set-ExcelRange.ps1 b/ExportedCommands/Set-ExcelRange.ps1 index 48d759e..ae80b3e 100644 --- a/ExportedCommands/Set-ExcelRange.ps1 +++ b/ExportedCommands/Set-ExcelRange.ps1 @@ -1,8 +1,8 @@ function Set-ExcelRange { - [cmdletbinding()] + [CmdletBinding()] [Alias("Set-Format")] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] - Param ( + param( [Parameter(ValueFromPipeline = $true,Position=0)] [Alias("Address")] $Range , diff --git a/ExportedCommands/Set-ExcelRow.ps1 b/ExportedCommands/Set-ExcelRow.ps1 index 72aa62e..c2c454b 100644 --- a/ExportedCommands/Set-ExcelRow.ps1 +++ b/ExportedCommands/Set-ExcelRow.ps1 @@ -1,10 +1,10 @@ -Function Set-ExcelRow { - [cmdletbinding()] +function Set-ExcelRow { + [CmdletBinding()] [Alias("Set-Row")] [OutputType([OfficeOpenXml.ExcelRow],[String])] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')] [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="Variables created for script block which may be passed as a parameter, but not used in the script")] - Param ( + param( [Parameter(ParameterSetName="Package",Mandatory=$true)] [OfficeOpenXml.ExcelPackage]$ExcelPackage, [Parameter(ParameterSetName="Package")] diff --git a/ExportedCommands/Set-WorksheetProtection.ps1 b/ExportedCommands/Set-WorksheetProtection.ps1 index b7258e3..7cb7db5 100644 --- a/ExportedCommands/Set-WorksheetProtection.ps1 +++ b/ExportedCommands/Set-WorksheetProtection.ps1 @@ -1,6 +1,6 @@ -Function Set-WorksheetProtection { - [Cmdletbinding()] - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')] +function Set-WorksheetProtection { + [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '',Justification='Does not change system state')] param ( [Parameter(Mandatory=$true)] [OfficeOpenXml.ExcelWorksheet]$Worksheet , diff --git a/ExportedCommands/Update-FirstObjectProperties.ps1 b/ExportedCommands/Update-FirstObjectProperties.ps1 index c859576..d4386d9 100644 --- a/ExportedCommands/Update-FirstObjectProperties.ps1 +++ b/ExportedCommands/Update-FirstObjectProperties.ps1 @@ -3,9 +3,10 @@ param() -Function Update-FirstObjectProperties { - - Try { +function Update-FirstObjectProperties { + [CmdletBinding()] + param() + try { $Union = @() $Input | ForEach-Object { If ($Union.Count) { @@ -17,7 +18,7 @@ Function Update-FirstObjectProperties { } $Union } - Catch { + catch { throw "Failed updating the properties of the first object: $_" } } \ No newline at end of file diff --git a/GetExcelTable.ps1 b/GetExcelTable.ps1 index 4fa2742..109f2d6 100644 --- a/GetExcelTable.ps1 +++ b/GetExcelTable.ps1 @@ -1,5 +1,5 @@ -Function Get-ExcelTableName { - Param ( +function Get-ExcelTableName { + param( $Path, $WorksheetName ) @@ -28,8 +28,8 @@ Function Get-ExcelTableName { $Excel = $null } -Function Get-ExcelTable { - Param ( +function Get-ExcelTable { + param( $Path, $TableName, $WorksheetName diff --git a/ImportExcel.psm1 b/ImportExcel.psm1 index 02dc71c..c121aa0 100644 --- a/ImportExcel.psm1 +++ b/ImportExcel.psm1 @@ -11,9 +11,9 @@ foreach ($directory in @('ExportedCommands','Charting','InferData','Pivot')) { if ($PSVersionTable.PSVersion.Major -ge 5) { . $PSScriptRoot\Plot.ps1 - Function New-Plot { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'New-Plot does not change system state')] - Param() + function New-Plot { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingfunctions', '', Justification = 'New-Plot does not change system state')] + param() [PSPlot]::new() } diff --git a/Install.ps1 b/Install.ps1 index c7589d3..ad4284a 100644 --- a/Install.ps1 +++ b/Install.ps1 @@ -4,7 +4,7 @@ File must not have BOM for GitHub deploy to work. #> [CmdletBinding(DefaultParameterSetName = 'Default')] -Param ( +param( # Path to install the module to, if not provided -Scope used. [Parameter(Mandatory, ParameterSetName = 'ModulePath')] [ValidateNotNullOrEmpty()] @@ -106,7 +106,7 @@ function Invoke-MultiLike { } } -Try { +try { Write-Verbose -Message 'Module installation started' if (!$ModulePath) { @@ -202,7 +202,7 @@ Try { Import-Module -Name $ModuleName -Force Write-Verbose -Message "Module installed" } -Catch { +catch { throw ('Failed installing module "{0}". Error: "{1}" in Line {2}' -f $ModuleName, $_, $_.InvocationInfo.ScriptLineNumber) } finally {