diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index e5b23be643..d0a94ba30b 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -165,16 +165,17 @@ "prefix": "foreach-progress", "description": "Insert a foreach loop with Write-Progress initialized", "body": [ - "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$array.count,4) * 100)", - "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$array.count - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", - "\\$i = 1", + "\\$total = \\$${1:array}.count", + "\\$${4:i} = 1", + "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$${4:i}/\\$total,4) * 100)", + "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$${4:i} of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", "foreach ($${2:item} in $${1:array}) {", - " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", - " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$${4:i}/\\$total,4) * 100)", + " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$${4:i} of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", " # Insert Code Here", " ${0}", " ", - " \\$i++", + " \\$${4:i}++", "}", "" ] @@ -670,4 +671,4 @@ "}" ] } -} +} \ No newline at end of file