Skip to content

Commit 96ce46f

Browse files
committed
Added check for Djoin result
1 parent 6d0539e commit 96ce46f

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

DSCResources/MSFT_xOfflineDomainJoin/MSFT_xOfflineDomainJoin.psm1

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,33 @@ function Join-Domain {
171171
-f $RequestFile `
172172
) -join '' )
173173

174-
& djoin.exe @('/REQUESTODJ','/LOADFILE',$RequestFile,'/WINDOWSPATH',$ENV:SystemRoot)
175-
176-
# Notify DSC that a reboot is required.
177-
$global:DSCMachineStatus = 1
174+
$Result = & djoin.exe @(
175+
'/REQUESTODJ'
176+
'/LOADFILE'
177+
$RequestFile
178+
'/WINDOWSPATH'
179+
$ENV:SystemRoot
180+
'/LOCALOS')
181+
if ($LASTEXITCODE -eq 0)
182+
{
183+
# Notify DSC that a reboot is required.
184+
$global:DSCMachineStatus = 1
185+
}
186+
else
187+
{
188+
Write-Verbose -Message $Result
189+
190+
$errorId = 'DjoinError'
191+
$errorCategory = [System.Management.Automation.ErrorCategory]::ObjectNotFound
192+
$errorMessage = $($LocalizedData.DjoinError) `
193+
-f $LASTEXITCODE
194+
$exception = New-Object -TypeName System.ArgumentException `
195+
-ArgumentList $errorMessage
196+
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
197+
-ArgumentList $exception, $errorId, $errorCategory, $null
198+
199+
$PSCmdlet.ThrowTerminatingError($errorRecord)
200+
} # if
178201

179202
Write-Verbose -Message ( @(
180203
"$($MyInvocation.MyCommand): "

DSCResources/MSFT_xOfflineDomainJoin/en-us/MSFT_xOfflineDomainJoin.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ ConvertFrom-StringData @'
77
DomainAlreadyJoinedhMessage=The computer is already joined to a domain '{0}'. Change not required.
88
DomainNotJoinedMessage=The computer is not joined to a domain. Change required.
99
RequestFileNotFoundError=The ODJ Request file '{0}' does not exist.
10+
DjoinError=Error {0} occured requesting the Offline Domain Join.
1011
'@

0 commit comments

Comments
 (0)