L
L
L0ns2021-12-24 11:24:15
PowerShell
L0ns, 2021-12-24 11:24:15

Why, after creating an AD object, it is impossible to immediately see information about it using Get-..?

Tell me how to fix it, there is a script that creates, for example, a group in AD, then displays information about the created group, for example:

New-ADGroup "$GroupName" -path "$OU" -Description "$Path" -GroupScope Global -PassThru –Verbose
Get-ADGroup "$GroupName" -Properties * | Select-Object Name, whenCreated, CanonicalName


There are several RWDCs in the domain, the rest are RODCs.
So, when the script is executed, a group is created, but info about the group is not displayed (an error that there is no group with that name), or rather it is displayed, but after 15 minutes, i.e. after there passes replication between DC. I understand that the Get-ADGroup command is executed from the nearest DC, in this case it is the RODC, which does not yet know about such a group.

The question is how to make the script run in one place so that you can immediately read the database in which the group was created?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Grishin, 2021-12-24
@L0ns

Did not have time to replicate, in fact. And to connect to a specific (writable) AD controller, cmdlets have the `-DomainController` or `-Server` parameter, which can be selected at the very beginning of the script and work only with it. And the full list of parameters can be viewed by Get-Help Get-ADGroup -Full, or -Detailed if examples are needed.

M
MaxKozlov, 2021-12-24
@MaxKozlov

@vesper-bot already gave you the reason.
If you want to fix it, then you don’t need to use Get-ADGroup
, New -ADGroup has already returned everything to you, you use -PassThru
If you need to use it, assign it to a variable and output it
or use it | Tee-Object -Variable 'group'to write down information to the $group variable and show on the screen at the same time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question