Skip to content

Commit 6cfd0c0

Browse files
authored
Cut 3864 fix hybrid leave domain (#118)
* hybrid leave bug fix * bug fix * changelog
1 parent 5753be7 commit 6cfd0c0

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

ModuleChangelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2.6.7
2+
3+
Release Date: Mar 29, 2024
4+
5+
#### RELEASE NOTES
6+
7+
```
8+
* Fixes an issue with hybrid unjoin would not leave local domain
9+
```
110
## 2.6.6
211

312
Release Date: Mar 28, 2024

jumpcloud-ADMU/JumpCloud.ADMU.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'JumpCloud.ADMU.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '2.6.6'
15+
ModuleVersion = '2.6.7'
1616

1717

1818
# Supported PSEditions

jumpcloud-ADMU/Powershell/Form.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function show-mtpSelection {
143143
<Window
144144
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
145145
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
146-
Title="JumpCloud ADMU 2.6.6"
146+
Title="JumpCloud ADMU 2.6.7"
147147
WindowStyle="SingleBorderWindow"
148148
ResizeMode="NoResize"
149149
Background="White" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" Width="1000" Height="520">

jumpcloud-ADMU/Powershell/Start-Migration.ps1

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ Function Start-Migration {
13831383
Begin {
13841384
Write-ToLog -Message:('####################################' + (get-date -format "dd-MMM-yyyy HH:mm") + '####################################')
13851385
# Start script
1386-
$admuVersion = '2.6.6'
1386+
$admuVersion = '2.6.7'
13871387
Write-ToLog -Message:('Running ADMU: ' + 'v' + $admuVersion)
13881388
Write-ToLog -Message:('Script starting; Log file location: ' + $jcAdmuLogFile)
13891389
Write-ToLog -Message:('Gathering system & profile information')
@@ -2025,10 +2025,10 @@ Function Start-Migration {
20252025
$AzureADStatus = ($line.trimstart('AzureADJoined : '))
20262026
}
20272027
if ($line -match "DomainJoined : ") {
2028-
$AzureDomainStatus = ($line.trimstart('DomainJoined : '))
2028+
$LocalDomainStatus = ($line.trimstart('DomainJoined : '))
20292029
}
20302030
}
2031-
Write-ToLog -Message "DomainJoined Status: $AzureDomainStatus"
2031+
Write-ToLog -Message "DomainJoined Status: $LocalDomainStatus"
20322032
Write-ToLog "AzureAD Status: $AzureADStatus"
20332033
if ($AzureADStatus -eq 'YES' -or $netBiosName -match 'AzureAD') {
20342034

@@ -2094,11 +2094,11 @@ Function Start-Migration {
20942094
#endregion AutobindUserToJCSystem
20952095

20962096
#region Leave Domain or AzureAD
2097-
2097+
$WmiComputerSystem = Get-WmiObject -Class:('Win32_ComputerSystem')
20982098
if ($LeaveDomain -eq $true) {
2099-
if ($AzureADStatus -match 'YES' -or $AzureDomainStatus -match 'YES') {
2099+
if ($AzureADStatus -match 'YES' -or $LocalDomainStatus -match 'YES') {
21002100
try {
2101-
if ($AzureDomainStatus -match 'NO') {
2101+
if ($LocalDomainStatus -match 'NO') {
21022102
dsregcmd.exe /leave # Leave Azure AD
21032103
} else {
21042104
Remove-Computer -force #Leave local AD or Hybrid
@@ -2112,19 +2112,54 @@ Function Start-Migration {
21122112
if ($line -match "AzureADJoined : ") {
21132113
$AzureADStatus = ($line.trimstart('AzureADJoined : '))
21142114
}
2115-
if ($line -match "EnterpriseJoined : ") {
2116-
$AzureEnterpriseStatus = ($line.trimstart('EnterpriseJoined : '))
2117-
}
21182115
if ($line -match "DomainJoined : ") {
2119-
$AzureDomainStatus = ($line.trimstart('DomainJoined : '))
2116+
$LocalDomainStatus = ($line.trimstart('DomainJoined : '))
21202117
}
21212118
}
21222119
# Check Azure AD status after running dsregcmd.exe /leave as NTAUTHORITY\SYSTEM
21232120
if ($AzureADStatus -match 'NO') {
2124-
Write-toLog -message "Left Azure AD domain successfully`nDevice Domain State`nAzureADJoined : $AzureADStatus`nEnterpriseJoined : $AzureEnterpriseStatus`nDomainJoined : $AzureDomainStatus"
2121+
Write-toLog -message "Left Azure AD domain successfully. Device Domain State, AzureADJoined : $AzureADStatus"
21252122
$admuTracker.leaveDomain.pass = $true
21262123
} 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+
}
21282163
}
21292164
}
21302165
}

0 commit comments

Comments
 (0)