Skip to content

Commit 27d4172

Browse files
authored
CUT-4223-LeaveLocalDomainFix (#131)
* leave local domain fix * cleanup leave domain + added 10px height to progressform * changelog
1 parent 21da7e4 commit 27d4172

File tree

5 files changed

+85
-77
lines changed

5 files changed

+85
-77
lines changed

ModuleChangelog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 2.7.3
2+
3+
Release Date: July 25, 2024
4+
5+
#### RELEASE NOTES
6+
7+
#### Bug Fixes:
8+
9+
```
10+
* Fixed an issue with leave local AD
11+
```
112
## 2.7.2
213

314
Release Date: July 16, 2024

jumpcloud-ADMU/JumpCloud.ADMU.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Version number of this module.
1515

16-
ModuleVersion = '2.7.2'
16+
ModuleVersion = '2.7.3'
1717

1818
# Supported PSEditions
1919
# CompatiblePSEditions = @()

jumpcloud-ADMU/Powershell/Form.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function show-mtpSelection {
153153
<Window
154154
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
155155
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
156-
Title="JumpCloud ADMU 2.7.2"
156+
Title="JumpCloud ADMU 2.7.3"
157157
WindowStyle="SingleBorderWindow"
158158
ResizeMode="NoResize"
159159
Background="White" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" Width="1020" Height="590">

jumpcloud-ADMU/Powershell/ProgressForm.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ function New-ProgressForm {
3737
<Window
3838
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3939
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
40-
Name="Window" Title="JumpCloud ADMU 2.7.2"
40+
Name="Window" Title="JumpCloud ADMU 2.7.3"
4141
WindowStyle="SingleBorderWindow"
4242
ResizeMode="NoResize"
43-
Background="White" Width="720" Height="540">
43+
Background="White" Width="720" Height="550 ">
4444
<Window.Resources>
4545
<Style x:Key="NoHeaderGroupBoxStyle" TargetType="{x:Type GroupBox}">
4646
<Setter Property="Template">

jumpcloud-ADMU/Powershell/Start-Migration.ps1

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,20 @@ function Get-ProfileSize {
18331833
Write-ToLog -Message:("Profile Size: $totalSizeGB GB")
18341834
return $totalSizeGB
18351835
}
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+
}
18361850
Function Start-Migration {
18371851
[CmdletBinding(HelpURI = "https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/Start-Migration")]
18381852
Param (
@@ -1869,7 +1883,7 @@ Function Start-Migration {
18691883
$AGENT_INSTALLER_URL = "https://cdn02.jumpcloud.com/production/jcagent-msi-signed.msi"
18701884
$AGENT_INSTALLER_PATH = "$windowsDrive\windows\Temp\JCADMU\jcagent-msi-signed.msi"
18711885
$AGENT_CONF_PATH = "$($AGENT_PATH)\Plugins\Contrib\jcagent.conf"
1872-
$admuVersion = '2.7.2'
1886+
$admuVersion = '2.7.3'
18731887

18741888
$script:AdminDebug = $AdminDebug
18751889
$isForm = $PSCmdlet.ParameterSetName -eq "form"
@@ -2758,21 +2772,9 @@ Function Start-Migration {
27582772
}
27592773
$appxList = @()
27602774

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-
}
27732775
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
27762778

27772779
if ($AzureADStatus -eq 'YES' -or $netBiosName -match 'AzureAD') {
27782780
# Find Appx User Apps by Username
@@ -2842,71 +2844,66 @@ Function Start-Migration {
28422844

28432845
$WmiComputerSystem = Get-WmiObject -Class:('Win32_ComputerSystem')
28442846
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
28772868
}
28782869
}
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+
}
28852880
}
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+
}
28862901

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 : '))
29002902
}
29012903
}
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-
}
29092904
}
2905+
} else {
2906+
Write-ToLog -Message:('Device is not joined to a domain, skipping leave domain step')
29102907
}
29112908
}
29122909

0 commit comments

Comments
 (0)