Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions snippets/PowerShell.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@
"}"
]
},
"Foreach with Progress": {
"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",
"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",
" # Insert Code Here",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{0} tabstop should include the Insert Code Here comment so when you start typing it overwrites it

" ${0}",
" ",
" \\$i++",
"}",
""
]
},
"ForEach-Object -Parallel": {
"prefix": "foreach-parallel",
"description": "[PS 7+] Process multiple objects in parallel using runspaces. This has some limitations compared to a regular ForEach-Object. More: Get-Help ForEach-Object",
Expand Down