@@ -29,6 +29,11 @@ function Invoke-DbatoolsFormatter {
29
29
PS C:\> Invoke-DbatoolsFormatter -Path C:\dbatools\public\Get-DbaDatabase.ps1
30
30
31
31
Reformats C:\dbatools\public\Get-DbaDatabase.ps1 to dbatools' standards
32
+
33
+ . EXAMPLE
34
+ PS C:\> Get-ChildItem *.ps1 | Invoke-DbatoolsFormatter
35
+
36
+ Reformats all .ps1 files in the current directory, showing progress for the batch operation
32
37
#>
33
38
[CmdletBinding ()]
34
39
param (
@@ -61,22 +66,44 @@ function Invoke-DbatoolsFormatter {
61
66
if ($psVersionTable.Platform -ne ' Unix' ) {
62
67
$OSEOL = " `r`n "
63
68
}
69
+
70
+ # Collect all paths for progress tracking
71
+ $allPaths = @ ()
64
72
}
65
73
process {
66
74
if (Test-FunctionInterrupt ) { return }
67
- foreach ($p in $Path ) {
75
+ # Collect all paths from pipeline
76
+ $allPaths += $Path
77
+ }
78
+ end {
79
+ if (Test-FunctionInterrupt ) { return }
80
+
81
+ $totalFiles = $allPaths.Count
82
+ $currentFile = 0
83
+ $processedFiles = 0
84
+ $updatedFiles = 0
85
+
86
+ foreach ($p in $allPaths ) {
87
+ $currentFile ++
88
+
68
89
try {
69
90
$realPath = (Resolve-Path - Path $p - ErrorAction Stop).Path
70
91
} catch {
92
+ Write-Progress - Activity " Formatting PowerShell files" - Status " Error resolving path: $p " - PercentComplete (($currentFile / $totalFiles ) * 100 ) - CurrentOperation " File $currentFile of $totalFiles "
71
93
Stop-Function - Message " Cannot find or resolve $p " - Continue
94
+ continue
72
95
}
73
96
74
97
# Skip directories
75
98
if (Test-Path - Path $realPath - PathType Container) {
99
+ Write-Progress - Activity " Formatting PowerShell files" - Status " Skipping directory: $realPath " - PercentComplete (($currentFile / $totalFiles ) * 100 ) - CurrentOperation " File $currentFile of $totalFiles "
76
100
Write-Message - Level Verbose " Skipping directory: $realPath "
77
101
continue
78
102
}
79
103
104
+ $fileName = Split-Path - Leaf $realPath
105
+ Write-Progress - Activity " Formatting PowerShell files" - Status " Processing: $fileName " - PercentComplete (($currentFile / $totalFiles ) * 100 ) - CurrentOperation " File $currentFile of $totalFiles "
106
+
80
107
$originalContent = Get-Content - Path $realPath - Raw - Encoding UTF8
81
108
$content = $originalContent
82
109
@@ -157,9 +184,20 @@ function Invoke-DbatoolsFormatter {
157
184
if ($originalNonEmpty -ne $newNonEmpty ) {
158
185
[System.IO.File ]::WriteAllText($realPath , $newContent , $Utf8NoBomEncoding )
159
186
Write-Message - Level Verbose " Updated: $realPath "
187
+ $updatedFiles ++
160
188
} else {
161
189
Write-Message - Level Verbose " No changes needed: $realPath "
162
190
}
191
+
192
+ $processedFiles ++
163
193
}
194
+
195
+ # Complete the progress bar
196
+ Write-Progress - Activity " Formatting PowerShell files" - Status " Complete" - PercentComplete 100 - CurrentOperation " Processed $processedFiles files, updated $updatedFiles "
197
+ Start-Sleep - Milliseconds 500 # Brief pause to show completion
198
+ Write-Progress - Activity " Formatting PowerShell files" - Completed
199
+
200
+ # Summary message
201
+ Write-Message - Level Verbose " Formatting complete: Processed $processedFiles files, updated $updatedFiles files"
164
202
}
165
203
}
0 commit comments