dsccommunity / ActiveDirectoryDsc

This module contains DSC resources for deployment and configuration of Active Directory Domain Services.
MIT License
341 stars 141 forks source link

ADOrganizationalUnit: Cannot use single quote in the Name parameter #674

Closed Borgquite closed 2 years ago

Borgquite commented 2 years ago

Details of the scenario you tried and the problem that is occurring

When trying to create an 'ADOrganizationalUnit', if the 'Name' is set to a value with a single quote ' an error occurs

Verbose logs showing the problem

PowerShell DSC resource MSFT_ADOrganizationalUnit failed to execute Test-TargetResource functionality with error message: System.InvalidOperationException: Error getting OU 'N'Djamena'. (ADOU0014) ---> Microsoft.ActiveDirectory.Management.ADFilterParsingException: Error parsing query: 'Name -eq 'N'Djamena'' Error Message: 'syntax error' at position: '13'. at Microsoft.ActiveDirectory.Management.QueryParser.yyerror(String s) at Microsoft.ActiveDirectory.Management.QueryParser.yyparse() at Microsoft.ActiveDirectory.Management.Commands.ADGetCmdletBase`3.ADGetCmdletBaseBeginCSRoutine() --- End of inner exception stack trace ---

Suggested solution to the issue

Appears to be an escaping issue in the following code: DSCResources/MSFT_ADOrganizationalUnit/MSFT_ADOrganizationalUnit.psm1 (line 49) If the filter: -Filter "Name -eq '$Name'" was changed to: -Filter "Name -eq [backtick]"$Name[backtick]"" (where [backtick] is `) it might resolve. (If you try to escape the input in the configuration e.g. by setting 'Name' to 'N''Djamena' the error does not occur - but the OU itself is created as 'N''Djamena' and subsequent consistency checks fail).

I think double quotes would still need to be escaped but this should resolve for single quotes

The DSC configuration that is used to reproduce the issue (as detailed as possible)

ADOrganizationalUnit "NDjamena"
{
    Name = "N'Djamena"
    Path = "DC=domain,DC=name=DC=here"
    Ensure = "Present"
}

The operating system the target node is running

OsName : Microsoft Windows Server 2019 Datacenter OsOperatingSystemSKU : DatacenterServerEdition OsArchitecture : 64-bit WindowsVersion : 1809 WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

PSVersion 5.1.17763.2268
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.2268
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used

6.0.1

Borgquite commented 2 years ago

Thank you :)

johlju commented 2 years ago

You’re welcome 😊