I linked the GitHub issue that I’m working on that has a lot of detail about it. I’ll try summarize it here …
The Registry resource is missing a fundamental action that would allow it to mimic some functionality of many GPO settings. One particular GPO setting is the OneDrive AllowTenantList. This is a registry key with one value under it for each item in the list. Of course, we can create a Registry resource config for each item in the list, but what about any registry values that aren’t managed? How do I clear out the extra values under that key? Of course, this could be done with a Script resource, but that’s just lame that the Registry resource can’t handle it natively. So I proposed the following configuration:
Registry OneDrive_AllowTenantList_1
{
Key = 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive\AllowTenantList'
ValueName = '1'
ValueData = 'My Tenant'
ValueType = 'String'
}
Registry OneDrive_AllowTenantList_2
{
Key = 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive\AllowTenantList'
ValueName = '2'
ValueData = 'Trusted Tenant'
ValueType = 'String'
}
Registry OneDrive_AllowTenantList_CleanUpExcess
{
Key = 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive\AllowTenantList'
ValueName = '' # Ideally without this property
RemoveExcessValueNames = $true
DependsOn = @(
'[Registry]OneDrive_AllowTenantList_1',
'[Registry]OneDrive_AllowTenantList_2'
)
}
The final Registry resource configuration would remove the values under the Key that aren’t being managed by the Registry resource configurations in the DependsOn Property; suggested implementation is in the GitHub issue.
Since I’m nearing defeat, I thought about implementing RemoveExcessValueNames with this code; but it’s not as DRY:
Registry OneDrive_AllowTenantList_CleanUpExcess
{
Key = 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive\AllowTenantList'
ValueName = '' # Ideally without this property
RemoveExcessValueNames = @('1', '2')
DependsOn = @(
'[Registry]OneDrive_AllowTenantList_1',
'[Registry]OneDrive_AllowTenantList_2'
)
}
Arguably, with this syntax you could add Values that you don’t want to manage, and also don’t want to delete. Otherwise, you would have to add another Registry resource to ensure that at least the Value exists; even if I don’t want to mange the Data. I believe that Registry resource configuration would look something like this:
Registry OneDrive_AllowTenantList_DoNotDelete
{
Key = 'HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\OneDrive\AllowTenantList'
ValueName = 'DoNotDelete'
}
Currently, I am trying to figure out how I can at least get my Instance Name (such as: [Registry]OneDrive_AllowTenantList_CleanUpExcess) from within the Set-TargetResource function. If I could get that, I could use Get-DscConfiguration to get my DependsOn information, and use that to get the Keys/Value information for the relevant Registry blocks … I think. 