Skip to content

Commit

Permalink
Merge pull request #1257 from ykuijs/fix-TestSPDscIsADUser
Browse files Browse the repository at this point in the history
Added domain support to Test-SPDscIsADUser
  • Loading branch information
ykuijs authored Nov 13, 2020
2 parents cadc1e4 + 2ce6024 commit 2731f68
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- SharePointDsc
- Added logging to the event log when the code throws an exception
- Added support for trusted domains to Test-SPDscIsADUser helper function
- SPInstall
- Added documentation about a SharePoint 2019 installer issue

### Changed

Expand Down
22 changes: 22 additions & 0 deletions SharePointDsc/DSCResources/MSFT_SPInstall/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ stream is added to indicate that the file is potentially from an unsafe source.
To use these files, make sure you first unblock them using Unblock-File.
SPInstall will throw an error when it detects the file is blocked.

NOTE 3:
The SharePoint 2019 installer has an issue with the Visual C++ Redistributable.
The Prerequisites Installer accepts a lower version than the SharePoint Setup
requires, resulting in the setup throwing an error message. The solution is to
download the most recent version of the Redistributable and using the Package
resource to install it through DSC:

```PowerShell
Package 'Install_VC2017ReDistx64'
{
Name = 'Microsoft Visual C++ 2015-2019 Redistributable (x64) - 14.24.28127'
Path = 'C:\Install\SharePoint\prerequisiteinstallerfiles\vc_redist.x64.exe'
Arguments = '/quiet /norestart'
ProductId = '282975d8-55fe-4991-bbbb-06a72581ce58'
Ensure = 'Present'
Credential = $InstallAccount
}
```

More information:
https://docs.microsoft.com/en-us/sharepoint/troubleshoot/installation-and-setup/sharepoint-server-setup-fails

## Multilingual support

Where possible, resources in SharePointDsc have been written in a way that
Expand Down
43 changes: 28 additions & 15 deletions SharePointDsc/Modules/SharePointDsc.Util/SharePointDsc.Util.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1345,33 +1345,46 @@ function Test-SPDscIsADUser
{
[OutputType([System.Boolean])]
[CmdletBinding()]
param (
[Parameter()]
param
(
[Parameter(Mandatory = $true)]
[System.String]
$IdentityName
)

$DomainNetbiosName = ""

if ($IdentityName -like "*\*")
{
$DomainNetbiosName = $IdentityName.Split('\')[0]
$IdentityName = $IdentityName.Substring($IdentityName.IndexOf('\') + 1)
}

$searcher = New-Object -TypeName System.DirectoryServices.DirectorySearcher
$searcher.filter = "((samAccountName=$IdentityName))"
$searcher.SearchScope = "subtree"
$searcher.PropertiesToLoad.Add("objectClass") | Out-Null
$searcher.PropertiesToLoad.Add("objectCategory") | Out-Null
$searcher.PropertiesToLoad.Add("name") | Out-Null
$result = $searcher.FindOne()
$domainContext = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain", $DomainNetbiosName)
try
{
$domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($domainContext)
$root = $domain.GetDirectoryEntry()

$searcher = [System.DirectoryServices.DirectorySearcher]::new()
$searcher.filter = "((samAccountName=$IdentityName))"
$searcher.SearchScope = "subtree"
$searcher.SearchRoot = $root

$searcher.PropertiesToLoad.Add("objectClass") | Out-Null
$searcher.PropertiesToLoad.Add("objectCategory") | Out-Null
$searcher.PropertiesToLoad.Add("name") | Out-Null
$result = $searcher.FindOne()
}
catch
{
return $false
}

if ($null -eq $result)
{
$message = "Unable to locate identity '$IdentityName' in the current domain."
Add-SPDscEvent -Message $message `
-EntryType 'Error' `
-EventID 100 `
-Source $MyInvocation.MyCommand.Source
throw $message
Write-Host "Unable to locate identity '$IdentityName' in the current domain."
return $false
}

if ($result[0].Properties.objectclass -contains "user")
Expand Down

0 comments on commit 2731f68

Please sign in to comment.