Created
September 21, 2020 19:19
-
-
Save mirontoli/346ac564930bb0834bad13d6ea805734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is just an example for time estimations in write-progress, | |
# though a simplified scenario | |
$sitesBareMinimum = Get-SPOSite -Limit All | |
$starttime = Get-Date | |
$count = 0 # kind of an index, counter | |
$total = $sitesBareMinimum.Count | |
$sites = $sitesBareMinimum | ForEach-Object { | |
$site = $_ | |
$estimation = "" | |
$now = Get-Date | |
if ($count -gt 0) { # noone wants a DividedByZeroException :) | |
$elapsed = $now - $starttime # how much time has been spent | |
$average = $elapsed.TotalSeconds / $count # how many seconds per site | |
$totalSecondsToGo = ($total - $count) * $average # seconds left | |
$span = New-TimeSpan -Seconds $totalSecondsToGo # time left | |
$estimatedCompletion = $now + $span # when it will be complete | |
$estimation = $estimatedCompletion.ToString() # readable estimation | |
} | |
$count++ | |
$percent = 100 * $count / $total # percentage complete | |
$status = "#{0:d5} of $total. Est:d $estimation. $($site.URL)" -f $count # aggregated status message | |
Write-Progress -Activity "Getting information for " -Status $status -PercentComplete $percent | |
$siteWithMoreInfo = Get-SPOSite -Identity $site.URL # the actual time consuming operation | |
$siteWithMoreInfo # return the site with more information | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment