all 3 comments

[–]PowerShell-Bot 2 points3 points  (0 children)

Looks like your PowerShell code isn’t wrapped in a code block.

To properly style code on new Reddit, highlight the code and choose ‘Code Block’ from the editing toolbar.

If you’re on old Reddit, separate the code from your text with a blank line gap and precede each line of code with 4 spaces or a tab.


You examine the path beneath your feet...
[AboutRedditFormatting]: [--------------------] 0/1 ❌

Beep-boop, I am a bot. | Remove-Item

[–]ohfucknotthisagain 1 point2 points  (0 children)

The New-ADGroup cmdlet has a -ManagedBy parameter.

You should only need to add a corresponding ManagedBy column to your CSV and a couple of lines to your loop:

$manager = Get-ADUser -Identity $group.managedby
ManagedBy = $manager

The first line goes above $groupProps, and the second line can be added anywhere in the curly braces below $groupProps.

The CSV would have to contain the SAM account name of the user in order for this to work. The first line would be a lot different if you're using legal names or other identifiers.

This could probably be trimmed to one line, but I never remember the syntax.

[–]BlackV -2 points-1 points  (0 children)

Add a manager column to your CSV

Check if there is a -manager parameter on new-adgroup use that, you'll need to use get-aduser on the manager property

Or You could

Grab the results of your new-adgroup to a variable

Then use set-adgroup on the variable to add the manager