Hi Guy's and hello from Paris !
I'm just starting to learn Powershell and...
I'm try to write a script to add multiple users in multiple group, and I have a problem to split an Excell cell.
I have a special conditon, This script will run via System Center Orchestrator. And, I'm need no error during the execution...
I hope you can help me...
My csv file exemple :
users;groups
testuser01;GGU_TestU,GGU_TestA,GGU_TestS,GGU_TestP,GGU_TestI
testuser02;GGU_TestU,GGU_TestA,GGU_TestS,GGU_TestP,GGU_TestI
testuser03;GGU_TestU,GGU_TestA,GGU_TestS,GGU_TestP,GGU_TestI
My script :
$csvfile = Import-Csv -path "C:\tests.csv" -delimiter ';'
foreach($item in $csvfile) {
$ACN = $item.users
$NDGS = $item.groups.split(',')
$verifmembers = Get-ADGroupMember -Identity $NDGS }
foreach ($NDG in $NDGS) {
if ($verifmembers -notcontains $NDG) {
Add-ADGroupMember $NDG -Members $ACN
}
}
Error :
Get-ADGroupMember : Cannot convert 'System.String[]' to the type 'Microsoft.ActiveDirectory.Management.ADGroup' required by parameter 'Identity'. Specified method
is not supported.
At C:\test1.ps1:11 char:52
+ $verifmembers = Get-ADGroupMember -Identity $NDGS }
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember
Any help would be greatly appreciated ! Thanks for your time and help
And sorry for my poor english...
↧
Add multiple AD users in multiple groups - Split Excell cell
↧