Skip to content

Commit 662d5cf

Browse files
authored
Merge pull request #114 from PowerShell/dev
Release of version 3.1.0.0 of xComputerManagement
2 parents a326994 + 80b5043 commit 662d5cf

File tree

7 files changed

+265
-246
lines changed

7 files changed

+265
-246
lines changed

DSCResources/MSFT_xOfflineDomainJoin/MSFT_xOfflineDomainJoin.psm1

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Scope="Function")]
1+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Scope = "Function")]
22
param
33
(
44
)
55

66
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) `
7-
-ChildPath 'CommonResourceHelper.psm1')
7+
-ChildPath 'CommonResourceHelper.psm1')
88
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_xOfflineDomainJoin'
99

10+
<#
11+
.SYNOPSIS
12+
Joins the computer to a domain with a domain join file.
13+
14+
.PARAMETER IsSingleInstance
15+
Specifies the resource is a single instance, the value must be 'Yes'.
16+
This value is Not used in Get-TargetResource.
17+
18+
.PARAMETER RequestFile
19+
The full path to the Offline Domain Join Request file to use.
20+
This value is not used in Get-TargetResource.
21+
#>
1022
function Get-TargetResource
1123
{
1224
[CmdletBinding()]
@@ -25,7 +37,7 @@ function Get-TargetResource
2537
)
2638

2739
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
28-
$($script:localizedData.GettingOfflineDomainJoinMessage)
40+
$($script:localizedData.GettingOfflineDomainJoinMessage)
2941
) -join '')
3042

3143
<#
@@ -34,12 +46,22 @@ function Get-TargetResource
3446
#>
3547
$returnValue = @{
3648
IsSingleInstance = 'Yes'
37-
RequestFile = ''
49+
RequestFile = ''
3850
}
3951

4052
return $returnValue
4153
} # Get-TargetResource
4254

55+
<#
56+
.SYNOPSIS
57+
Sets the current state of the offline domain join.
58+
59+
.PARAMETER IsSingleInstance
60+
Specifies the resource is a single instance, the value must be 'Yes'.
61+
62+
.PARAMETER RequestFile
63+
The full path to the Offline Domain Join Request file to use.
64+
#>
4365
function Set-TargetResource
4466
{
4567
[CmdletBinding()]
@@ -57,22 +79,15 @@ function Set-TargetResource
5779
)
5880

5981
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
60-
$($script:localizedData.ApplyingOfflineDomainJoinMessage)
82+
$($script:localizedData.ApplyingOfflineDomainJoinMessage)
6183
) -join '')
6284

6385
# Check the ODJ Request file exists
6486
if (-not (Test-Path -Path $RequestFile))
6587
{
66-
$errorId = 'RequestFileNotFoundError'
67-
$errorCategory = [System.Management.Automation.ErrorCategory]::ObjectNotFound
68-
$errorMessage = $($script:localizedData.RequestFileNotFoundError) `
69-
-f $RequestFile
70-
$exception = New-Object -TypeName System.ArgumentException `
71-
-ArgumentList $errorMessage
72-
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
73-
-ArgumentList $exception, $errorId, $errorCategory, $null
74-
75-
$PSCmdlet.ThrowTerminatingError($errorRecord)
88+
New-InvalidArgumentException `
89+
-Message ($script:localizedData.RequestFileNotFoundError -f $RequestFile) `
90+
-ArgumentName 'RequestFile'
7691
} # if
7792

7893
<#
@@ -82,6 +97,17 @@ function Set-TargetResource
8297
Join-Domain -RequestFile $RequestFile
8398
} # Set-TargetResource
8499

100+
<#
101+
.SYNOPSIS
102+
Tests the current state of the machine joining a domain using
103+
an offline domain join file.
104+
105+
.PARAMETER IsSingleInstance
106+
Specifies the resource is a single instance, the value must be 'Yes'.
107+
108+
.PARAMETER RequestFile
109+
The full path to the Offline Domain Join Request file to use.
110+
#>
85111
function Test-TargetResource
86112
{
87113
[CmdletBinding()]
@@ -103,66 +129,59 @@ function Test-TargetResource
103129
[System.Boolean] $desiredConfigurationMatch = $true
104130

105131
Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
106-
$($script:localizedData.CheckingOfflineDomainJoinMessage)
132+
$($script:localizedData.CheckingOfflineDomainJoinMessage)
107133
) -join '')
108134

109135
# Check the ODJ Request file exists
110136
if (-not (Test-Path -Path $RequestFile))
111137
{
112-
$errorId = 'RequestFileNotFoundError'
113-
$errorCategory = [System.Management.Automation.ErrorCategory]::ObjectNotFound
114-
$errorMessage = $($script:localizedData.RequestFileNotFoundError) `
115-
-f $RequestFile
116-
$exception = New-Object -TypeName System.ArgumentException `
117-
-ArgumentList $errorMessage
118-
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
119-
-ArgumentList $exception, $errorId, $errorCategory, $null
120-
121-
$PSCmdlet.ThrowTerminatingError($errorRecord)
138+
New-InvalidArgumentException `
139+
-Message ($script:localizedData.RequestFileNotFoundError -f $RequestFile) `
140+
-ArgumentName 'RequestFile'
122141
} # if
123142

124-
$CurrentDomainName = Get-DomainName
143+
$currentDomainName = Get-DomainName
125144

126-
if($CurrentDomainName)
145+
if ($currentDomainName)
127146
{
128147
# Domain is already joined.
129148
Write-Verbose -Message ( @(
130-
"$($MyInvocation.MyCommand): "
131-
$($script:localizedData.DomainAlreadyJoinedMessage) `
132-
-f $CurrentDomainName `
149+
"$($MyInvocation.MyCommand): "
150+
$($script:localizedData.DomainAlreadyJoinedMessage -f $CurrentDomainName) `
133151
) -join '' )
134152
}
135153
else
136154
{
137155
# Domain is not joined, so change is required.
138156
Write-Verbose -Message ( @("$($MyInvocation.MyCommand): "
139-
$($script:localizedData.DomainNotJoinedMessage)
157+
$($script:localizedData.DomainNotJoinedMessage)
140158
) -join '')
141159

142160
$desiredConfigurationMatch = $false
143161
} # if
162+
144163
return $desiredConfigurationMatch
145164
} # Test-TargetResource
146165

147166
<#
148167
.SYNOPSIS
149168
Uses DJoin.exe to join a Domain using a ODJ Request File.
150169
#>
151-
function Join-Domain {
170+
function Join-Domain
171+
{
152172
[CmdletBinding()]
153173
param(
154-
[Parameter(Mandatory=$true)]
174+
[Parameter(Mandatory = $true)]
155175
[System.String]
156176
$RequestFile
157177
)
158178

159179
Write-Verbose -Message ( @(
160-
"$($MyInvocation.MyCommand): "
161-
$($script:localizedData.AttemptingDomainJoinMessage) `
162-
-f $RequestFile `
180+
"$($MyInvocation.MyCommand): "
181+
$($script:localizedData.AttemptingDomainJoinMessage -f $RequestFile) `
163182
) -join '' )
164183

165-
$Result = & djoin.exe @(
184+
$djoinResult = & djoin.exe @(
166185
'/REQUESTODJ'
167186
'/LOADFILE'
168187
$RequestFile
@@ -177,24 +196,15 @@ function Join-Domain {
177196
}
178197
else
179198
{
180-
Write-Verbose -Message $Result
181-
182-
$errorId = 'DjoinError'
183-
$errorCategory = [System.Management.Automation.ErrorCategory]::ObjectNotFound
184-
$errorMessage = $($script:localizedData.DjoinError) `
185-
-f $LASTEXITCODE
186-
$exception = New-Object -TypeName System.ArgumentException `
187-
-ArgumentList $errorMessage
188-
$errorRecord = New-Object -TypeName System.Management.Automation.ErrorRecord `
189-
-ArgumentList $exception, $errorId, $errorCategory, $null
190-
191-
$PSCmdlet.ThrowTerminatingError($errorRecord)
199+
Write-Verbose -Message $djoinResult
200+
201+
New-InvalidOperationException `
202+
-Message ($script:localizedData.DjoinError -f $LASTEXITCODE)
192203
} # if
193204

194205
Write-Verbose -Message ( @(
195-
"$($MyInvocation.MyCommand): "
196-
$($script:localizedData.DomainJoinedMessage) `
197-
-f $RequestFile `
206+
"$($MyInvocation.MyCommand): "
207+
$($script:localizedData.DomainJoinedMessage -f $RequestFile) `
198208
) -join '' )
199209
} # function Join-Domain
200210

@@ -211,6 +221,7 @@ function Get-DomainName
211221

212222
# Use CIM to detect the domain name so that this will work on Nano Server.
213223
$computerSystem = Get-CimInstance -ClassName 'Win32_ComputerSystem' -Namespace root\cimv2
224+
214225
if ($computerSystem.Workgroup)
215226
{
216227
return $null
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[ClassVersion("1.0.0.0"), FriendlyName("xOfflineDomainJoin")]
22
class MSFT_xOfflineDomainJoin : OMI_BaseResource
33
{
4-
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'"), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
4+
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
55
[Required, Description("The full path to the Offline Domain Join Request file to use.")] String RequestFile;
66
};

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ xVirtualMemory has the following properties:
211211

212212
### Unreleased
213213

214+
### 3.1.0.0
215+
216+
* xOfflineDomainJoin:
217+
* Updated to meet HQRM guidelines.
218+
214219
### 3.0.0.0
215220

216221
* xComputer: Added parameter to set the local computer description along with documentation

0 commit comments

Comments
 (0)