From fddf22df64b940fa4b30a44481ab3ea204fd875d Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Thu, 2 Jan 2020 22:03:10 +0800 Subject: [PATCH 1/2] Remove use of $PSBoundParameters --- .../Public/Setup-ScheduledTask.ps1 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 b/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 index 3d5c7c7..8441506 100644 --- a/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 +++ b/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 @@ -22,31 +22,31 @@ function Setup-ScheduledTask { try { # Import definitions as an array of hashtable definitions $DefinitionsCollection = New-Object System.Collections.ArrayList - if ($PSBoundParameters['DefinitionFile']) { - $DefinitionFileCollection = Get-Item $PSBoundParameters['DefinitionFile'] - }elseif ($PSBoundParameters['DefinitionDirectory']) { - $DefinitionFileCollection = if ($PSBoundParameters['AsJson']) { - Get-ChildItem $PSBoundParameters['DefinitionDirectory'] -File | ? { $_.Extension -eq '.json' } + if ($DefinitionFile) { + $DefinitionFileCollection = Get-Item $DefinitionFile + }elseif ($DefinitionDirectory) { + $DefinitionFileCollection = if ($AsJson) { + Get-ChildItem $DefinitionDirectory -File | ? { $_.Extension -eq '.json' } }else { - Get-ChildItem $PSBoundParameters['DefinitionDirectory'] -File | ? { $_.Extension -eq '.ps1' } + Get-ChildItem $DefinitionDirectory -File | ? { $_.Extension -eq '.ps1' } } } - if (!$PSBoundParameters['DefinitionObject']) { + if (!$DefinitionObject) { if (!$DefinitionFileCollection) { "No definitions could be found from the specified definition files or directories." | Write-Error return } } - if (!$PSBoundParameters['DefinitionObject']) { + if (!$DefinitionObject) { $DefinitionCollectionRaw = $DefinitionFileCollection | % { - if ($PSBoundParameters['AsJson']) { + if ($AsJson) { Get-Content -Path $_.FullName | ConvertFrom-Json }else { . $_.FullName } } - }elseif ($PSBoundParameters['DefinitionObject']) { - $DefinitionCollectionRaw = $PSBoundParameters['DefinitionObject'] + }elseif ($DefinitionObject) { + $DefinitionCollectionRaw = $DefinitionObject } $DefinitionCollectionRaw | % { $definitionHashtable = if ($_.GetType() -ne [hashtable]) { $_ | ConvertTo-Hashtable } else { $_ } From 75fd46064e7add94b891d7eb90fb466380039bd8 Mon Sep 17 00:00:00 2001 From: Joel Timothy Oh Date: Thu, 2 Jan 2020 22:08:58 +0800 Subject: [PATCH 2/2] Use implicit parameters where possible --- src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 | 2 +- src/ScheduledTaskManagement/ScheduledTaskManagement.psm1 | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 b/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 index 8441506..072a422 100644 --- a/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 +++ b/src/ScheduledTaskManagement/Public/Setup-ScheduledTask.ps1 @@ -40,7 +40,7 @@ function Setup-ScheduledTask { if (!$DefinitionObject) { $DefinitionCollectionRaw = $DefinitionFileCollection | % { if ($AsJson) { - Get-Content -Path $_.FullName | ConvertFrom-Json + Get-Content $_.FullName | ConvertFrom-Json }else { . $_.FullName } diff --git a/src/ScheduledTaskManagement/ScheduledTaskManagement.psm1 b/src/ScheduledTaskManagement/ScheduledTaskManagement.psm1 index 5fdd132..7624e85 100644 --- a/src/ScheduledTaskManagement/ScheduledTaskManagement.psm1 +++ b/src/ScheduledTaskManagement/ScheduledTaskManagement.psm1 @@ -12,9 +12,9 @@ $script:MODULE['PRIVATE_DIR'] = Join-Path $script:MODULE['BASE_DIR'] 'Private' $script:MODULE['HELPERS_DIR'] = Join-Path $script:MODULE['BASE_DIR'] 'helpers' # Module helpers # Load vendor, Public, Private, classes, helpers -Get-ChildItem -Path "$($script:MODULE['PUBLIC_DIR'])\*.ps1" | % { . $_.FullName } -Get-ChildItem -Path "$($script:MODULE['PRIVATE_DIR'])\*.ps1" | % { . $_.FullName } -Get-ChildItem -Path "$($script:MODULE['HELPERS_DIR'])\*.ps1" | % { . $_.FullName } +Get-ChildItem "$($script:MODULE['PUBLIC_DIR'])\*.ps1" | % { . $_.FullName } +Get-ChildItem "$($script:MODULE['PRIVATE_DIR'])\*.ps1" | % { . $_.FullName } +Get-ChildItem "$($script:MODULE['HELPERS_DIR'])\*.ps1" | % { . $_.FullName } # Export Public functions Export-ModuleMember -Function (Get-ChildItem "$($script:MODULE['PUBLIC_DIR'])\*.ps1" | Select-Object -ExpandProperty BaseName)