0

I'm trying to take a list of groups and use the name of the group to create a Group Policy Object with the same name, but I want to replace the Group portion of the name with GPO, however, it comes out as one long string, and creates the name of the GPO as one long name.

  $groupname = Get-ADGroup -searchbase "OU=examplegroup,DC=example,DC=com" -Filter * | where { $_.name -ne "example"} | select -ExpandProperty name
    $groupname = $groupname.replace("Group","Gpo")
    foreach ($group in $groupname) { New-GPO -name "$groupname"}
Davidw
  • 127
  • 1
  • 1
  • 10

1 Answers1

2

The name for the new GPO is in the variable $group, not $groupname. Run the New-GPO-bit using the WhatIf-parameter to try it out first.

$groupname = Get-ADGroup -searchbase "OU=examplegroup,DC=example,DC=com" -Filter * | where { $_.name -ne "example"} | select -ExpandProperty name
$groupname = $groupname.replace("Group","Gpo")
foreach ($group in $groupname) { New-GPO -name $group -WhatIf}
notjustme
  • 2,376
  • 2
  • 20
  • 27