error with import-csv to new-adgroup

Trying to do bulk create AD groups.  I realize there are several scripts out there that already do this but want to learn by doing.

I cannot get past the error "Cannot validate argument on parameter 'GroupScope'"

import-module activedirectory

$date = Get-Date -Format MMddyyyy
$csvinput = "C:\pthtest\$date.csv"

Import-Csv $csvinput 

foreach ($item in $csvinput)
{
New-ADGroup -Name "$item.Name" -GroupScope $item.GroupScope -GroupCategory $item.GroupCategory -Description "$item.Description"  -ManagedBy "$item.ManagedBy" -Path "item.OUPath" -OtherAttributes @{'Info'="$item.OtherInfo"}
}

csv looks like this:

Name,GroupScope,GroupCategory,Description,ManagedBy,OUPath,OtherInfo
pth-group1 Test,DomainLocal,Security,"Owner: Paul1 | p@test.com,bogususer",bogususer,"OU=Privilaged Users,DC=lapstest,DC=com",RITM1/Task1 07092015
pth-group2 Test,DomainLocal,Security,"Owner: Paul2 | p@test.com,bogususer",bogususer,"OU=Privilaged Users,DC=lapstest,DC=com",RITM2/Task2 07092015

what am I doing wrong? Any help greatly appreciated!

-Paul

July 9th, 2015 2:08pm

What is in $item.GroupScope?  I has to be ver carefully designed to work here.  Be sure you have legitimate values.

Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 3:52pm

Hi Paul,

I recommend you can use try and catch in powershell to handle the error:

http://www.vexasoft.com/blogs/powershell/7255220-powershell-tutorial-try-catch-finally-and-error-handling-in-powershell

Best Regards,

Anna

July 12th, 2015 9:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics