Open rgl opened 4 years ago
Heya, thanks for bringing that up with the distinguished name and the OU - definitely need to catch this in a more graceful manner!
As for the group mapping: At the moment - unfortunately - it requires explicitly using the -Identity
parameter and specifying which identities to include.
The next version - which is already commissioned, I just need to find the time, probably first week of March - will see that fixed, along with some other issues in the current version.
Anyway, this should do it (and keep working after the update):
Get-GPO RDP | Backup-GptPolicy -Path "$PWD\xxx" -Identity 'Domain Users'
Why did the mapping not help?
It requires the export/backup to also have exported the identity. It is designed to allow you to map to entirely different names. I probably should add the ability to add mappings explicitly, no matter the previous export ...
Also: Thank you for the very detailed report! I wish every report were that clear :)
I failed to mention that I was using the current development version.
I redid the export using Get-GPO RDP | Backup-GptPolicy -Path "$PWD\xxx" -Identity 'Domain Users'
but it didn't change anything, the exported files are the same (minus the backup id and dates).
So I'm not sure if I should have used the released version (installed with Install-Module GPOTools
) or the development version.
BTW, thank you for creating this library that puts some sanity in this whole GPO enchilada!
I redid the test using the version from Install-Module GPOTools
as:
Get-GPO RDP | Backup-GptPolicy -Path "$PWD\yyy" -Identity 'Domain Users'
Then tried to restore with:
Restore-GptPolicy -Path yyy -Name RDP
Restore-GptPolicy -Path yyy -Name RDP -IdentityMapping @{'EXAMPLE\Domain Users' = 'Domain Users'}
Restore-GptPolicy -Path yyy -Name RDP -IdentityMapping @{'EXAMPLE\Domain Users' = 'MARS\Domain Users'}
But all failed at:
Action : Importing Policy Objects
Step : Import Object
Target : @{DisplayName=RDP; Id=78987f77-3d9d-4a0e-8bd1-34c18d85ab44; Owner=EXAMPLE\Enterprise Admins; CreationTime=17/02/2020 17:50:27;
ModificationTime=17/02/2020 17:51:24; WmiFilter=}
Success : True
Data : {@{DisplayName=RDP; Id=78987f77-3d9d-4a0e-8bd1-34c18d85ab44; Owner=EXAMPLE\Enterprise Admins; CreationTime=17/02/2020 17:50:27;
ModificationTime=17/02/2020 17:51:24; WmiFilter=}, C:\Users\vagrant\Desktop\yyy\GPO\MARS.TEST.migtable}
Error :
Could not find imported identities to match. Please run Import-GptIdentitiy first!
At C:\Program Files\WindowsPowerShell\Modules\GPOTools\0.1.0\GPOTools.psm1:1803 char:4
+ throw 'Could not find imported identities to match. Pleas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Could not find ...dentitiy first!:String) [], RuntimeException
+ FullyQualifiedErrorId : Could not find imported identities to match. Please run Import-GptIdentitiy first!
Hm ... curious :(
Really should work with the -Identity
parameter.
Also the error really shouldn't be happening! (Importing identities is the first step in the restore process) "Should" ... truly an awesome word ^^ Will look into it tonight, when I'm off the clock.
Apologies, didn't get to it and business interfered, will unfortunately not be able to get back to this before Sunday, sorry :(
No worries! Thanks for looking into it!
@FriedrichWeinmann, I've retried with 0.3.0 and it still shows the following errors:
Get-OU : Cannot bind argument to parameter 'DistinguishedName' because it is an empty string.
At C:\Program Files\WindowsPowerShell\Modules\GPOTools\0.3.0\GPOTools.psm1:2189 char:71
+ ... | Where-Object { -not (Get-OU -DistinguishedName $_.TargetOU -Server ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-OU], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Get-OU
Get-OU : Cannot bind argument to parameter 'DistinguishedName' because it is an empty string.
At C:\Program Files\WindowsPowerShell\Modules\GPOTools\0.3.0\GPOTools.psm1:2192 char:83
+ ... Exists | Where-Object { Get-OU -DistinguishedName $_.TargetOU -Server ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-OU], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Get-OU
Those errors seem to map to the following source lines:
To fix this, is it correct to ignore all links which have an empty TargetOU
property value? If so, can I submit a MR?
I've created a GPO (in the
EXAMPLE
domain) which adds theEXAMPLE\Domain Users
group into theRemote Desktop Users
group inComputer Configuration\Preferences\Control Panel Settings\Local Users and Groups
pane:Then I've exported the GPO with:
Then in another domain, the
MARS
domain, I've tried to import it as:Even with those last error,
Restore-GptPolicy
seems to have done everything except the last step that callsImport-GptLink @common -Name $Name
, which I think its safe to ignore for now, as its only related to create the link between the GPO and the domain (and I think its only failing because there is noOU
in this example domain).After the import, it has successfully created/restored the
RDP
GPO, but it didn't modify/translate/mapEXAMPLE\Domains Users
toMARS\Domain Users
:I've even tried to execute
Restore-GptPolicy
as:But it didn't work, as the end result was the same.
This particular GPO stores its data in
GPO\{567AD9E6-EFB4-4343-8FBB-450E06A69DA8}\DomainSysvol\GPO\Machine\Preferences\Groups\Groups.xml
as:Do you known why it didn't work? Or how I can make this work? Or do I have to handle
groups.xml
myself?BTW, I'm using https://github.com/rgl/windows-domain-controller-vagrant to launch these example domains.