Skip to content

Commit cac9e3d

Browse files
committed
DomainName check validates child without FQDN
The condition for verifying we're in the correct domain throws a non-terminating error if a child domain was used as input without FQDN. All other functions worked correctly in that scenario except validating the computer is in the correct domain. This change allows lacking FQDN to still return true value.
1 parent 5f9fa56 commit cac9e3d

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

DSCResources/MSFT_xComputer/MSFT_xComputer.psm1

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,23 @@ function Test-TargetResource
234234
{
235235
throw "Need to specify credentials with domain"
236236
}
237-
237+
238238
try
239239
{
240240
Write-Verbose "Checking if the machine is a member of $DomainName."
241-
return ($DomainName.ToLower() -eq (GetComputerDomain).ToLower())
241+
if ($DomainName.Contains('.'))
242+
{
243+
$getComputerDomainSplat = @{
244+
netbios = $false
245+
}
246+
}
247+
else
248+
{
249+
$getComputerDomainSplat = @{
250+
netbios = $true
251+
}
252+
}
253+
return ($DomainName -eq (GetComputerDomain @getComputerDomainSplat ))
242254
}
243255
catch
244256
{
@@ -268,9 +280,25 @@ function ValidateDomainOrWorkGroup($DomainName, $WorkGroupName)
268280

269281
function GetComputerDomain
270282
{
271-
try
283+
[CmdletBinding()]
284+
param
285+
(
286+
[Parameter()]
287+
[Switch]
288+
$NetBios
289+
)
290+
291+
try
272292
{
273-
return ([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()).Name
293+
if ($NetBios)
294+
{
295+
$domainName = $ENV:USERDOMAIN
296+
}
297+
else
298+
{
299+
$domainName = ([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()).Name
300+
}
301+
return $domainName
274302
}
275303
catch [System.Management.Automation.MethodInvocationException]
276304
{

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ xVirtualMemory has the following properties:
9090
## Versions
9191

9292
### Unreleased
93+
* xComputer: Changed comparision that validates if we are in the correct AD Domain to work correctly if FQDN wasn't used
9394

9495
### 1.10.0.0
9596
* Added resources

0 commit comments

Comments
 (0)