From e430158b4bd000daae5c21af79f781ab364fca9d Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 2 Aug 2019 16:46:44 +0200 Subject: [PATCH] Changes to ADUser - Now uses the helper function `Add-TypeAssembly` which have some benefit instead of directly using `Add-Type`, like verbose logging (issue #431). --- CHANGELOG.md | 2 ++ DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0e6491d7..e7d45dbe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,8 @@ - Now it correctly tests passwords when parameter DomainName is set to distinguished name and parameter Credential is used ([issue #451](https://github.com/PowerShell/ActiveDirectoryDsc/issues/451)). - Added integration tests ([issue #359](https://github.com/PowerShell/ActiveDirectoryDsc/issues/359)). + - Now uses the helper function `Add-TypeAssembly` which have some benefit + instead of directly using `Add-Type`, like verbose logging ([issue #431](https://github.com/PowerShell/ActiveDirectoryDsc/issues/431)). - Changes to ADDomain - BREAKING CHANGE: Renamed the parameter `DomainAdministratorCredential` to `Credential` to better indicate that it is possible to impersonate diff --git a/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 b/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 index 6a9817a60..40cee1c83 100644 --- a/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 +++ b/DSCResources/MSFT_ADUser/MSFT_ADUser.psm1 @@ -2350,7 +2350,9 @@ function Test-Password Write-Verbose -Message ($script:localizedData.CreatingADDomainConnection -f $DomainName) - Add-Type -AssemblyName 'System.DirectoryServices.AccountManagement' + $typeName = 'System.DirectoryServices.AccountManagement.PrincipalContext' + + Add-TypeAssembly -AssemblyName 'System.DirectoryServices.AccountManagement' -TypeName $typeName <# If the domain name contains a distinguished name, set it to the fully @@ -2370,7 +2372,7 @@ function Test-Password $script:localizedData.TestPasswordUsingImpersonation -f $Credential.UserName, $UserName ) - $principalContext = New-Object -TypeName 'System.DirectoryServices.AccountManagement.PrincipalContext' -ArgumentList @( + $principalContext = New-Object -TypeName $typeName -ArgumentList @( [System.DirectoryServices.AccountManagement.ContextType]::Domain, $DomainName, $Credential.UserName, @@ -2379,7 +2381,7 @@ function Test-Password } else { - $principalContext = New-Object -TypeName 'System.DirectoryServices.AccountManagement.PrincipalContext' -ArgumentList @( + $principalContext = New-Object -TypeName $typeName -ArgumentList @( [System.DirectoryServices.AccountManagement.ContextType]::Domain, $DomainName, $null,