New-adgroup -Managedby not substituting the variable

Welcome Forums General PowerShell Q&A New-adgroup -Managedby not substituting the variable

Viewing 2 reply threads
  • Author
    Posts
    • #228625
      Participant
      Topics: 32
      Replies: 105
      Points: 533
      Rank: Major Contributor

      Need to create several groups on a daily basis so I decide to create a powershell script to do this.

      Import-Csv “C:\Util\efaxgroups.csv” | ForEach-Object {

      $gname = $_.”Name”
      $manager = $_.”Manager”
      $OU = $_.”OU”

      new-adgroup -Name “$gname” -ManagedBy “manager” -Path “OU=$OU,DC=test,dc=edu” -Description “Provides users to  Fax Service” -GroupScope Global -GroupCategory Security

      }

      the error

      new-adgroup : Identity info provided in the extended attribute: ‘ManagedBy’ could not be resolved. Reason: ‘Cannot find an object with identity: ‘manager’ under: ‘DC=test,DC=edu’.’.
      At line:7 char:1
      + new-adgroup -Name “$gname” -ManagedBy “manager” -Path “OU=$OU,OU=TES …
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : InvalidData: (CN=FDU-GSG-eFax…t,DC=fdu,dc=edu:String) [New-ADGroup], ADIdentityResolutionException
      + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityResolutionException,Microsoft.ActiveDirectory.Management.Commands.NewADGroup

      When I run the command manually it works great.

       

      new-adgroup -Name “Test-Group” -ManagedBy “testuser” -Path “OU=Test,OU=Security-Groups,DC=test,dc=edu” -Description “Provides users to Fax Service” -GroupScope Global -GroupCategory Security

       

      The input file is a csv file

      Name   Manager   OU

       

      Any ideas on why the Manageby is not being substituted properly?  I tried “” ” no quotes

       

      Thank you

       

      Tom

       

    • #228637
      Participant
      Topics: 12
      Replies: 524
      Points: 1,219
      Helping Hand
      Rank: Community Hero

      You’re forgetting the $ before manager
      You can simplify as:

      Import-Csv “C:\Util\efaxgroups.csv” | ForEach-Object {
          new-adgroup -Name $_.Name -ManagedBy $_.Manager -Path “OU=$($_.OU),DC=test,DC=edu” -Description “Provides users to Fax Service” -GroupScope Global -GroupCategory Security
      }
      
      • This reply was modified 2 weeks, 3 days ago by Sam Boutros.
      • This reply was modified 2 weeks, 3 days ago by Sam Boutros.
    • #228649
      Participant
      Topics: 32
      Replies: 105
      Points: 533
      Rank: Major Contributor

      Sam

       

      Thanks OMG I did not even see that

       

      It works now and thanks for the shortcut too

Viewing 2 reply threads
  • You must be logged in to reply to this topic.