Skip to content

Commit c0cfdca

Browse files
committed
1 parent a3fa45c commit c0cfdca

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

AADInternals.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
aadsync_server= "adminwebservice.microsoftonline.com"
2323
aadsync_client_version="8.0"
24-
aadsync_client_build= "2.2.8.0"
24+
aadsync_client_build= "2.4.21.0"
2525
client_id = "04b07795-8ddb-461a-bbee-02f9e1bf7b46"
2626

2727
class AADInternals():
@@ -299,19 +299,25 @@ def get_groupsmembers(self,objectid,pagesize=500,sortdirection="Ascending",sortf
299299

300300

301301

302-
#https://github.com/Gerenios/AADInternals/blob/fd6474e840f457c32a297cadbad051cabe2a019b/ProvisioningAPI.ps1#L3404
302+
#https://github.com/microsoftgraph/entra-powershell/blob/af0c8b538d293390ce0c2fafe30b95259cdcf774/module/Entra/Microsoft.Entra/DirectoryManagement/Set-EntraDirSyncEnabled.ps1#L44
303303
def set_adsyncenabled(self,enabledirsync=True):
304-
"""
305-
Enables or disables directory synchronization using provisioning API.
306-
Enabling / disabling the synchrnoization usually takes less than 10 seconds. Check the status using Get-AADIntCompanyInformation.
307-
"""
308-
body = '''<b:EnableDirSync>%s</b:EnableDirSync>''' % str(bool(enabledirsync)).lower()
309-
command = "SetCompanyDirSyncEnabled"
310-
envelope = self.create_envelope(command,body)
311-
response = self.call_provisioningapi(envelope)
312-
return self.xml_to_result(response,command)
313304

305+
url = f"https://graph.microsoft.com/v1.0/organization/{self.tenant_id}"
306+
token = self.get_token(['https://graph.microsoft.com/.default'])
307+
headers = {
308+
"Authorization": f"Bearer {token}",
309+
"Content-Type": "application/json"
310+
}
314311

312+
body = {"OnPremisesSyncEnabled": enabledirsync}
313+
314+
response = requests.patch(url, json=body, headers=headers,proxies=self.proxies)
315+
316+
if response.status_code == 204:
317+
return
318+
else:
319+
raise Exception (response.content)
320+
315321
#https://github.com/Gerenios/AADInternals/blob/fd6474e840f457c32a297cadbad051cabe2a019b/ProvisioningAPI.ps1#L5561
316322
def set_userlicenses(self,objectid):
317323
body = rf'''<b:AddLicenses i:nil="true"/>

0 commit comments

Comments
 (0)