Hybrid Azure Join script

# You can use this as a RUN Script in SCCM or package it and make it available in software center

# Performs DSREGCMD /join (requires elevation) and triggers Intune-Device-Sync

# Status of each step is logged as well.

$LogFilePathJoin = “C:\Windows\Temp\Logs\CA_Hybrid_Join.log”

$LogFilePathStatus = “C:\Windows\Temp\Logs\CA_Hybrid_status.log”

Start-Process -FilePath “C:\Windows\system32\dsregcmd.exe” -ArgumentList (“/join /debug”) -NoNewWindow -PassThru -RedirectStandardOutput “$LogFilePathJoin” -Wait -Verbose

Start-Sleep -Seconds 5

Get-ScheduledTask -TaskPath “\Microsoft\Windows\Workplace Join\” -TaskName “Automatic-Device-Join” | Start-ScheduledTask -ErrorAction SilentlyContinue

Start-Sleep -Seconds 5

Get-ScheduledTask -TaskPath “\Microsoft\Windows\Workplace Join\” -TaskName “Device-Sync” | Start-ScheduledTask -ErrorAction SilentlyContinue

Start-Sleep -Seconds 5

Start-Process -FilePath “C:\Windows\system32\dsregcmd.exe” -ArgumentList (“/status”) -NoNewWindow -PassThru -RedirectStandardOutput “$LogFilePathStatus” -Wait -Verbose