From d1493d7746c86b61cdc7f4b3afcb849d0d5bf56e Mon Sep 17 00:00:00 2001 From: Mikael Porttila Date: Sun, 24 Apr 2016 09:02:18 +0200 Subject: [PATCH 1/2] Added Remove-Template function --- pecan-waffle.psm1 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pecan-waffle.psm1 b/pecan-waffle.psm1 index 0532dde..c5a8e76 100644 --- a/pecan-waffle.psm1 +++ b/pecan-waffle.psm1 @@ -1101,6 +1101,31 @@ function New-PWItem{ } Set-Alias Add-Item New-PWItem -Description 'obsolete: This was added for back compat and will be removed soon' +function Remove-PWTemplate{ + [cmdletbinding()] + param( + [Parameter(Position=1,Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string[]]$TemplateNames + ) + process{ + + <# Store copy of old array #> + $templates = $Global:pecanwafflesettings.Templates + + <# Clear the old template array #> + $Global:pecanwafflesettings.Templates = New-Object System.Collections.ArrayList + + <# Filter the temp list #> + foreach($template in $templates){ + if(!$TemplateNames.Contains($template.Name)){ + $Global:pecanwafflesettings.Templates.Add(($template)) + } + } + } +} +Set-Alias Remove-Template Remove-PWTemplate + function InternalGet-EvaluatedPropertiesFrom{ [cmdletbinding()] param( From e4e1b741793c0bcde67c10a9846edbeff8445fc3 Mon Sep 17 00:00:00 2001 From: Mikael Porttila Date: Sun, 24 Apr 2016 09:22:14 +0200 Subject: [PATCH 2/2] Replaced my arraylist with an array. --- pecan-waffle.psm1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pecan-waffle.psm1 b/pecan-waffle.psm1 index c5a8e76..39101b3 100644 --- a/pecan-waffle.psm1 +++ b/pecan-waffle.psm1 @@ -1110,16 +1110,16 @@ function Remove-PWTemplate{ ) process{ - <# Store copy of old array #> + <# Make a copy of the old template array #> $templates = $Global:pecanwafflesettings.Templates + + <# Create new template array #> + $Global:pecanwafflesettings.Templates = @() - <# Clear the old template array #> - $Global:pecanwafflesettings.Templates = New-Object System.Collections.ArrayList - - <# Filter the temp list #> + <# Filter out templates #> foreach($template in $templates){ - if(!$TemplateNames.Contains($template.Name)){ - $Global:pecanwafflesettings.Templates.Add(($template)) + if($TemplateNames -notcontains $template.Name){ + $Global:pecanwafflesettings.Templates += $template } } }