Created
June 1, 2022 12:58
-
-
Save Trimad/a33d28b7fce4c5e21013d018780cf0bf to your computer and use it in GitHub Desktop.
Expedite syncing Active Directory with O365
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
# Get the ID and security principal of the current user account | |
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() | |
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) | |
# Get the security principal for the Administrator role | |
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator | |
# Check to see if we are currently running "as Administrator" | |
if ($myWindowsPrincipal.IsInRole($adminRole)) | |
{ | |
# We are running "as Administrator" - so change the title and background color to indicate this | |
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)" | |
$Host.UI.RawUI.BackgroundColor = "DarkBlue" | |
clear-host | |
} | |
else | |
{ | |
# We are not running "as Administrator" - so relaunch as administrator | |
# Create a new process object that starts PowerShell | |
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; | |
# Specify the current script path and name as a parameter | |
$newProcess.Arguments = $myInvocation.MyCommand.Definition; | |
# Indicate that the process should be elevated | |
$newProcess.Verb = "runas"; | |
# Start the new process | |
[System.Diagnostics.Process]::Start($newProcess); | |
# Exit from the current, unelevated, process | |
exit | |
} | |
# Run your code that needs to be elevated here | |
#Create Prompts for User Selection | |
Write-Host '1) Delta Sync(Recommended, unless told to do a full sync)' | |
Write-Host '2) Full Sync' | |
Write-Host '3) Exit' | |
# Read the input of the user | |
$selected_menu_item = Read-Host 'Which number would you like to run (1 or 2)(Enter Number and Press Enter' | |
#Commands for each selection option | |
Switch($selected_menu_item){ | |
1{Start-ADSyncSyncCycle -PolicyType Delta} | |
2{Start-ADSyncSyncCycle -PolicyType Initial} | |
3{Write-Host 'Exit'; exit} | |
#Display Red text for an unexpected input | |
default {Write-Host 'Incorrect Input' -ForegroundColor Red} | |
} | |
#Final Remarks | |
Write-Host 'Running Now.... Check miisclient to confirm' | |
Start-Sleep -s 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment