-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadsync.ps1
35 lines (29 loc) · 1.64 KB
/
adsync.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
################################################################################
# Force sync to Azure AD #
# Author: Cory Burditt #
# Version 1.5 #
# Date: November 19, 2024 #
# Description: This script Forces a sync with Azure AD of any changes made #
# as well as adding in a function to update the #
# domain controllsers as well #
################################################################################
#Are you admin No then RuN AS ADMIN
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
function Update-AllDomainController {
(Get-ADDomainController -Filter *).Name | Foreach-Object {repadmin /syncall $_ (Get-ADDomain).DistinguishedName /e /A | Out-Null}
Start-Sleep 10
Get-ADReplicationPartnerMetadata -Target "$env:userdnsdomain" -Scope Domain | Select-Object Server, LastReplicationSuccess
}
#The Commands
Import-Module AdSync
Start-ADSyncSyncCycle -PolicyType Delta
Update-AllDomainController
#Completion notice and exit prompt.
Write-Host ("Completed" )
write-host "Press any key to close..."
[void][System.Console]::ReadKey($true)