@@ -1833,6 +1833,20 @@ function Get-ProfileSize {
1833
1833
Write-ToLog - Message:(" Profile Size: $totalSizeGB GB" )
1834
1834
return $totalSizeGB
1835
1835
}
1836
+
1837
+ function Get-DomainStatus {
1838
+ $ADStatus = dsregcmd.exe / status
1839
+ foreach ($line in $ADStatus ) {
1840
+ if ($line -match " AzureADJoined : " ) {
1841
+ $AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
1842
+ }
1843
+ if ($line -match " DomainJoined : " ) {
1844
+ $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
1845
+ }
1846
+ }
1847
+ # Return both statuses
1848
+ return $AzureADStatus , $LocalDomainStatus
1849
+ }
1836
1850
Function Start-Migration {
1837
1851
[CmdletBinding (HelpURI = " https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/Start-Migration" )]
1838
1852
Param (
@@ -1869,7 +1883,7 @@ Function Start-Migration {
1869
1883
$AGENT_INSTALLER_URL = " https://cdn02.jumpcloud.com/production/jcagent-msi-signed.msi"
1870
1884
$AGENT_INSTALLER_PATH = " $windowsDrive \windows\Temp\JCADMU\jcagent-msi-signed.msi"
1871
1885
$AGENT_CONF_PATH = " $ ( $AGENT_PATH ) \Plugins\Contrib\jcagent.conf"
1872
- $admuVersion = ' 2.7.2 '
1886
+ $admuVersion = ' 2.7.3 '
1873
1887
1874
1888
$script :AdminDebug = $AdminDebug
1875
1889
$isForm = $PSCmdlet.ParameterSetName -eq " form"
@@ -2758,21 +2772,9 @@ Function Start-Migration {
2758
2772
}
2759
2773
$appxList = @ ()
2760
2774
2761
- # Get Azure AD Status
2762
-
2763
- $ADStatus = dsregcmd.exe / status
2764
- foreach ($line in $ADStatus ) {
2765
- if ($line -match " AzureADJoined : " ) {
2766
- $AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2767
- }
2768
- if ($line -match " DomainJoined : " ) {
2769
-
2770
- $AzureDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2771
- }
2772
- }
2773
2775
Write-ToProgress - ProgressBar $Progressbar - Status " CheckADStatus" - form $isForm
2774
-
2775
- Write-ToLog " AzureAD Status: $AzureADStatus " - Level Verbose
2776
+ # Get Azure AD Status
2777
+ $AzureADStatus , $LocalDomainStatus = Get-DomainStatus
2776
2778
2777
2779
if ($AzureADStatus -eq ' YES' -or $netBiosName -match ' AzureAD' ) {
2778
2780
# Find Appx User Apps by Username
@@ -2842,71 +2844,66 @@ Function Start-Migration {
2842
2844
2843
2845
$WmiComputerSystem = Get-WmiObject - Class:(' Win32_ComputerSystem' )
2844
2846
if ($LeaveDomain -eq $true ) {
2845
- if ($AzureADStatus -match ' YES' -or $LocalDomainStatus -match ' YES' ) {
2846
- try {
2847
- if ($LocalDomainStatus -match ' NO' ) {
2848
- dsregcmd.exe / leave # Leave Azure AD
2849
- } else {
2850
- Remove-Computer - force # Leave local AD or Hybrid
2851
- }
2852
- } catch {
2853
- Write-ToLog - Message:(' Unable to leave domain, JumpCloud agent will not start until resolved' ) - Level:(' Warn' )
2854
- }
2855
- # Get Azure AD Status
2856
- $ADStatus = dsregcmd.exe / status
2857
- foreach ($line in $ADStatus ) {
2858
- if ($line -match " AzureADJoined : " ) {
2859
- $AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2860
- }
2861
- if ($line -match " DomainJoined : " ) {
2862
- $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2863
- }
2864
- }
2865
- # Check Azure AD status after running dsregcmd.exe /leave as NTAUTHORITY\SYSTEM
2866
- if ($AzureADStatus -match ' NO' ) {
2867
- Write-toLog - message " Left Azure AD domain successfully. Device Domain State, AzureADJoined : $AzureADStatus "
2868
- $admuTracker.leaveDomain.pass = $true
2869
- } else {
2870
- Write-ToLog - Message:(' Unable to leave Azure Domain. Re-running dsregcmd.exe /leave' ) - Level:(' Warn' )
2871
- dsregcmd.exe / leave # Leave Azure AD
2872
-
2873
- $ADStatus = dsregcmd.exe / status
2874
- foreach ($line in $ADStatus ) {
2875
- if ($line -match " AzureADJoined : " ) {
2876
- $AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2847
+ if ($AzureADStatus -match ' YES' -and $LocalDomainStatus -match ' YES' ) {
2848
+ Write-ToLog - Message:(' Device is HYBRID joined' )
2849
+ $ADJoined = " Hybrid"
2850
+ } elseif ($AzureADStatus -match ' NO' -and $LocalDomainStatus -match ' Yes' ) {
2851
+ Write-ToLog - Message:(' Device is Local Domain joined' )
2852
+ $ADJoined = " LocalJoined"
2853
+ } elseif ($AzureADStatus -match ' YES' -and $LocalDomainStatus -match ' NO' ) {
2854
+ Write-ToLog - Message:(' Device is Azure AD joined' )
2855
+ $ADJoined = " AzureADJoined"
2856
+ }
2857
+ if ($ADJoined ) {
2858
+ switch ($ADJoined ) {
2859
+ " Hybrid" {
2860
+ Remove-Computer - force # LeaveHybrid
2861
+ $AzureADStatus , $LocalDomainStatus = Get-DomainStatus
2862
+ if ($AzureADStatus -match ' NO' -and $LocalDomainStatus -match ' NO' ) {
2863
+ Write-ToLog - Message:(' Left Hybrid Domain successfully' ) - Level:(' Info' )
2864
+ $admuTracker.leaveDomain.pass = $true
2865
+ } else {
2866
+ Write-ToLog - Message:(' Unable to leave Hybrid Domain' ) - Level:(' Warn' )
2867
+ $admuTracker.leaveDomain.fail = $true
2877
2868
}
2878
2869
}
2879
- if ($AzureADStatus -match ' NO' ) {
2880
- Write-ToLog - Message:(' Left Azure AD domain successfully' ) - Level:(' Info' )
2881
- $admuTracker.leaveDomain.pass = $true
2882
- } else {
2883
- Write-ToLog - Message:(' Unable to leave Azure AD domain' ) - Level:(' Warn' )
2884
- $admuTracker.leaveDomain.fail = $true
2870
+ " LocalJoined" {
2871
+ $WmiComputerSystem.UnJoinDomainOrWorkGroup ($null , $null , 0 )
2872
+ $AzureADStatus , $LocalDomainStatus = Get-DomainStatus
2873
+ if ($AzureADStatus -match ' NO' -and $LocalDomainStatus -match ' NO' ) {
2874
+ Write-ToLog - Message:(' Left local domain successfully' ) - Level:(' Info' )
2875
+ $admuTracker.leaveDomain.pass = $true
2876
+ } else {
2877
+ Write-ToLog - Message:(' Unable to leave local domain' ) - Level:(' Warn' )
2878
+ $admuTracker.leaveDomain.fail = $true
2879
+ }
2885
2880
}
2881
+ " AzureADJoined" {
2882
+ dsregcmd.exe / leave # Leave Azure AD
2883
+ # Get Azure AD Status after running dsregcmd.exe /leave
2884
+ $AzureADStatus = Get-DomainStatus
2885
+ # Check Azure AD status after running dsregcmd.exe /leave as NTAUTHORITY\SYSTEM
2886
+ if ($AzureADStatus -match ' NO' ) {
2887
+ Write-toLog - message " Left Azure AD domain successfully. Device Domain State, AzureADJoined : $AzureADStatus "
2888
+ $admuTracker.leaveDomain.pass = $true
2889
+ } else {
2890
+ Write-ToLog - Message:(' Unable to leave Azure Domain. Re-running dsregcmd.exe /leave' ) - Level:(' Warn' )
2891
+ dsregcmd.exe / leave # Leave Azure AD
2892
+
2893
+ $AzureADStatus = Get-DomainStatus
2894
+ if ($AzureADStatus -match ' NO' ) {
2895
+ Write-ToLog - Message:(' Left Azure AD domain successfully' ) - Level:(' Info' )
2896
+ $admuTracker.leaveDomain.pass = $true
2897
+ } else {
2898
+ Write-ToLog - Message:(' Unable to leave Azure AD domain' ) - Level:(' Warn' )
2899
+ $admuTracker.leaveDomain.fail = $true
2900
+ }
2886
2901
2887
- }
2888
-
2889
- if ($LocalDomainStatus -match ' NO' ) {
2890
- Write-toLog - message " Local Domain State, Local Domain Joined : $LocalDomainStatus "
2891
- $admuTracker.leaveDomain.pass = $true
2892
- } else {
2893
- Write-ToLog - Message:(' Unable to leave local domain using remove-computer...Running UnJoinDomainOrWorkGroup' ) - Level:(' Warn' )
2894
- $WmiComputerSystem.UnJoinDomainOrWorkGroup ($null , $null , 0 )
2895
-
2896
- $ADStatus = dsregcmd.exe / status
2897
- foreach ($line in $ADStatus ) {
2898
- if ($line -match " DomainJoined : " ) {
2899
- $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2900
2902
}
2901
2903
}
2902
- if ($LocalDomainStatus -match ' NO' ) {
2903
- Write-ToLog - Message:(' Left local domain successfully' ) - Level:(' Info' )
2904
- $admuTracker.leaveDomain.pass = $true
2905
- } else {
2906
- Write-ToLog - Message:(' Unable to leave local domain' ) - Level:(' Warn' )
2907
- $admuTracker.leaveDomain.fail = $true
2908
- }
2909
2904
}
2905
+ } else {
2906
+ Write-ToLog - Message:(' Device is not joined to a domain, skipping leave domain step' )
2910
2907
}
2911
2908
}
2912
2909
0 commit comments