@@ -128,12 +128,15 @@ function Invoke-CIPPDBCacheCollection {
128128
129129 Write-Information " Starting $CollectionType collection for $TenantFilter ($ ( $CacheTypes.Count ) cache types)"
130130
131+ $CollectionStopwatch = [System.Diagnostics.Stopwatch ]::StartNew()
131132 $SuccessCount = 0
132133 $FailedCount = 0
133134 $Errors = [System.Collections.Generic.List [string ]]::new()
135+ $Timings = [System.Collections.Generic.List [string ]]::new()
134136
135137 foreach ($CacheType in $CacheTypes ) {
136138 $FullFunctionName = " Set-CIPPDBCache$CacheType "
139+ $ItemStopwatch = [System.Diagnostics.Stopwatch ]::StartNew()
137140 try {
138141 $Function = Get-Command - Name $FullFunctionName - ErrorAction SilentlyContinue
139142 if (-not $Function ) {
@@ -145,16 +148,26 @@ function Invoke-CIPPDBCacheCollection {
145148
146149 Write-Information " [$CollectionType ] Collecting $CacheType for $TenantFilter "
147150 & $FullFunctionName @Params
151+ $ItemStopwatch.Stop ()
152+ $ElapsedSeconds = [math ]::Round($ItemStopwatch.Elapsed.TotalSeconds , 3 )
153+ $Timings.Add (" $CacheType : ${ElapsedSeconds} s" )
154+ Write-Information " [$CollectionType ] Completed $CacheType for $TenantFilter - Took ${ElapsedSeconds} seconds"
148155 $SuccessCount ++
149156 } catch {
157+ $ItemStopwatch.Stop ()
158+ $ElapsedSeconds = [math ]::Round($ItemStopwatch.Elapsed.TotalSeconds , 3 )
150159 $FailedCount ++
151160 $Errors.Add (" $CacheType : $ ( $_.Exception.Message ) " )
152- Write-Warning " [$CollectionType ] Failed $CacheType for $TenantFilter : $ ( $_.Exception.Message ) "
161+ $Timings.Add (" $CacheType : ${ElapsedSeconds} s (FAILED)" )
162+ Write-Warning " [$CollectionType ] Failed $CacheType for $TenantFilter after ${ElapsedSeconds} seconds: $ ( $_.Exception.Message ) "
153163 }
154164 }
155165
156- $Summary = " $CollectionType collection for $TenantFilter completed - $SuccessCount succeeded, $FailedCount failed out of $ ( $CacheTypes.Count ) "
166+ $CollectionStopwatch.Stop ()
167+ $TotalElapsed = [math ]::Round($CollectionStopwatch.Elapsed.TotalSeconds , 3 )
168+ $Summary = " $CollectionType collection for $TenantFilter completed in ${TotalElapsed} seconds - $SuccessCount succeeded, $FailedCount failed out of $ ( $CacheTypes.Count ) "
157169 Write-Information $Summary
170+ Write-Information " Timings: $ ( $Timings -join ' | ' ) "
158171
159172 if ($FailedCount -gt 0 ) {
160173 Write-LogMessage - API ' CIPPDBCache' - tenant $TenantFilter - message " $Summary . Errors: $ ( $Errors -join ' ; ' ) " - sev Warning
@@ -166,6 +179,8 @@ function Invoke-CIPPDBCacheCollection {
166179 Success = $SuccessCount
167180 Failed = $FailedCount
168181 Total = $CacheTypes.Count
182+ TotalSeconds = $TotalElapsed
183+ Timings = @ ($Timings )
169184 Errors = @ ($Errors )
170185 }
171186}
0 commit comments