Hi,
with the code below I’m checking the difference between the last Sync Time between on premises AD management server and AzureAD.
this is working just fine as long as you don’t execute the script somewhere between the 27th and 30 min after the last sync then it will result in an error and you have to wait till the next cycle in order to continue
what would be the easiest way to reset the counter or relaunch this script when started in the above mentioned time frame after last sync
[pre]
$username = $env:USERNAME
$cred = Import-Clixml -Path “c:\temp\cred$username.Cred”
#Connect-MsolService -Credential $cred
$GracePeriodMin = 31
[DateTime]$LastDirSyncTime = (Get-MsolCompanyInformation).LastDirSyncTime # Assuming this time is UTC
Using .ToUniversalTime() method of the DateTime object to obtain current UTC time
$MinutesSinceLastSync = [Math]::Round((New-TimeSpan -Start $LastDirSyncTime -End (Get-Date).ToUniversalTime()).TotalMinutes,0)
Write-Output “Last Dir Sync Time was ‘$LastDirSyncTime’ UTC - that’s ‘$MinutesSinceLastSync’ minutes ago”
Write-host -ForegroundColor cyan “you can now modify the globalDDI.xlsx sheet”
$counter = $GracePeriodMin - $MinutesSinceLastSync
$Zcounter = $counter++
while ($zcounter -ne 0) {
#Write-host -ForegroundColor yellow “$zcounter: '$zcounter'" -NoNewline #Write-host -ForegroundColor Green "$counter: ‘$counter’”
$counter++
$zcounter–-
Write-host -ForegroundColor yellow “please return in ‘$Zcounter’ min for the second part of the offboarding script”
Start-Sleep -seconds 60
#if($zcounter -eq “-1”){break}
}
write-host -ForegroundColor Magenta “Coffee Break is over get moving… :)”
[/pre]
thanks for your Idea’s
Paul