@@ -1383,7 +1383,7 @@ Function Start-Migration {
1383
1383
Begin {
1384
1384
Write-ToLog - Message:(' ####################################' + (get-date - format " dd-MMM-yyyy HH:mm" ) + ' ####################################' )
1385
1385
# Start script
1386
- $admuVersion = ' 2.6.6 '
1386
+ $admuVersion = ' 2.6.7 '
1387
1387
Write-ToLog - Message:(' Running ADMU: ' + ' v' + $admuVersion )
1388
1388
Write-ToLog - Message:(' Script starting; Log file location: ' + $jcAdmuLogFile )
1389
1389
Write-ToLog - Message:(' Gathering system & profile information' )
@@ -2025,10 +2025,10 @@ Function Start-Migration {
2025
2025
$AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2026
2026
}
2027
2027
if ($line -match " DomainJoined : " ) {
2028
- $AzureDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2028
+ $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2029
2029
}
2030
2030
}
2031
- Write-ToLog - Message " DomainJoined Status: $AzureDomainStatus "
2031
+ Write-ToLog - Message " DomainJoined Status: $LocalDomainStatus "
2032
2032
Write-ToLog " AzureAD Status: $AzureADStatus "
2033
2033
if ($AzureADStatus -eq ' YES' -or $netBiosName -match ' AzureAD' ) {
2034
2034
@@ -2094,11 +2094,11 @@ Function Start-Migration {
2094
2094
# endregion AutobindUserToJCSystem
2095
2095
2096
2096
# region Leave Domain or AzureAD
2097
-
2097
+ $WmiComputerSystem = Get-WmiObject - Class:( ' Win32_ComputerSystem ' )
2098
2098
if ($LeaveDomain -eq $true ) {
2099
- if ($AzureADStatus -match ' YES' -or $AzureDomainStatus -match ' YES' ) {
2099
+ if ($AzureADStatus -match ' YES' -or $LocalDomainStatus -match ' YES' ) {
2100
2100
try {
2101
- if ($AzureDomainStatus -match ' NO' ) {
2101
+ if ($LocalDomainStatus -match ' NO' ) {
2102
2102
dsregcmd.exe / leave # Leave Azure AD
2103
2103
} else {
2104
2104
Remove-Computer - force # Leave local AD or Hybrid
@@ -2112,19 +2112,54 @@ Function Start-Migration {
2112
2112
if ($line -match " AzureADJoined : " ) {
2113
2113
$AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2114
2114
}
2115
- if ($line -match " EnterpriseJoined : " ) {
2116
- $AzureEnterpriseStatus = ($line.trimstart (' EnterpriseJoined : ' ))
2117
- }
2118
2115
if ($line -match " DomainJoined : " ) {
2119
- $AzureDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2116
+ $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2120
2117
}
2121
2118
}
2122
2119
# Check Azure AD status after running dsregcmd.exe /leave as NTAUTHORITY\SYSTEM
2123
2120
if ($AzureADStatus -match ' NO' ) {
2124
- Write-toLog - message " Left Azure AD domain successfully`n Device Domain State`n AzureADJoined : $AzureADStatus `n EnterpriseJoined : $AzureEnterpriseStatus `n DomainJoined : $AzureDomainStatus "
2121
+ Write-toLog - message " Left Azure AD domain successfully. Device Domain State, AzureADJoined : $AzureADStatus "
2125
2122
$admuTracker.leaveDomain.pass = $true
2126
2123
} else {
2127
- Write-ToLog - Message:(' Unable to leave domain, JumpCloud agent will not start until resolved' ) - Level:(' Warn' )
2124
+ Write-ToLog - Message:(' Unable to leave Azure Domain. Re-running dsregcmd.exe /leave' ) - Level:(' Warn' )
2125
+ dsregcmd.exe / leave # Leave Azure AD
2126
+
2127
+ $ADStatus = dsregcmd.exe / status
2128
+ foreach ($line in $ADStatus ) {
2129
+ if ($line -match " AzureADJoined : " ) {
2130
+ $AzureADStatus = ($line.trimstart (' AzureADJoined : ' ))
2131
+ }
2132
+ }
2133
+ if ($AzureADStatus -match ' NO' ) {
2134
+ Write-ToLog - Message:(' Left Azure AD domain successfully' ) - Level:(' Info' )
2135
+ $admuTracker.leaveDomain.pass = $true
2136
+ } else {
2137
+ Write-ToLog - Message:(' Unable to leave Azure AD domain' ) - Level:(' Warn' )
2138
+ $admuTracker.leaveDomain.fail = $true
2139
+ }
2140
+
2141
+ }
2142
+
2143
+ if ($LocalDomainStatus -match ' NO' ) {
2144
+ Write-toLog - message " Local Domain State, Local Domain Joined : $LocalDomainStatus "
2145
+ $admuTracker.leaveDomain.pass = $true
2146
+ } else {
2147
+ Write-ToLog - Message:(' Unable to leave local domain using remove-computer...Running UnJoinDomainOrWorkGroup' ) - Level:(' Warn' )
2148
+ $WmiComputerSystem.UnJoinDomainOrWorkGroup ($null , $null , 0 )
2149
+
2150
+ $ADStatus = dsregcmd.exe / status
2151
+ foreach ($line in $ADStatus ) {
2152
+ if ($line -match " DomainJoined : " ) {
2153
+ $LocalDomainStatus = ($line.trimstart (' DomainJoined : ' ))
2154
+ }
2155
+ }
2156
+ if ($LocalDomainStatus -match ' NO' ) {
2157
+ Write-ToLog - Message:(' Left local domain successfully' ) - Level:(' Info' )
2158
+ $admuTracker.leaveDomain.pass = $true
2159
+ } else {
2160
+ Write-ToLog - Message:(' Unable to leave local domain' ) - Level:(' Warn' )
2161
+ $admuTracker.leaveDomain.fail = $true
2162
+ }
2128
2163
}
2129
2164
}
2130
2165
}
0 commit comments