Skip to content

Commit fd1ea30

Browse files
committed
Fixed a few issues with the ex-path-processing example
1 parent 06626d1 commit fd1ea30

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

snippets/PowerShell.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,14 @@
228228
"Example-Path Processing": {
229229
"prefix": "ex-path processing",
230230
"body": [
231+
"# Modify [CmdletBinding()] to [CmdletBinding(SupportsShouldProcess=$true, DefaultParameterSetName='Path')]",
231232
"$paths = @()",
232233
"if ($psCmdlet.ParameterSetName -eq 'Path') {",
233234
"\tforeach ($aPath in $Path) {",
234235
"\t\tif (!(Test-Path -Path $aPath)) {",
235-
"\t\t\t$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '$Path' because it does not exist.\"",
236+
"\t\t\t$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '$aPath' because it does not exist.\"",
236237
"\t\t\t$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound",
237-
"\t\t\t$errRecord = New-Object System.Management.Automation.ErrorRecord $ex,'PathNotFound',$category,$Path",
238+
"\t\t\t$errRecord = New-Object System.Management.Automation.ErrorRecord $ex,'PathNotFound',$category,$aPath",
238239
"\t\t\t$psCmdlet.WriteError($errRecord)",
239240
"\t\t\tcontinue",
240241
"\t\t}",
@@ -246,9 +247,9 @@
246247
"else {",
247248
"\tforeach ($aPath in $LiteralPath) {",
248249
"\t\tif (!(Test-Path -LiteralPath $aPath)) {",
249-
"\t\t\t$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '$LiteralPath' because it does not exist.\"",
250+
"\t\t\t$ex = New-Object System.Management.Automation.ItemNotFoundException \"Cannot find path '$aPath' because it does not exist.\"",
250251
"\t\t\t$category = [System.Management.Automation.ErrorCategory]::ObjectNotFound",
251-
"\t\t\t$errRecord = New-Object System.Management.Automation.ErrorRecord $ex,'PathNotFound',$category,$LiteralPath",
252+
"\t\t\t$errRecord = New-Object System.Management.Automation.ErrorRecord $ex,'PathNotFound',$category,$aPath",
252253
"\t\t\t$psCmdlet.WriteError($errRecord)",
253254
"\t\t\tcontinue",
254255
"\t\t}",

0 commit comments

Comments
 (0)