Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Ignoring blank fields of csv file

$
0
0

Hi, I am new to powershell and I need some help if you are kind :)

I have one  script for adding users to my AD and I want to import a csv file. The script is working, but I want to add one user to more groups, and I have some empty fields in my CSV file and I think this is the cause for this error:

Add-QADGroupMember : Cannot resolve directory object for the given identity: ''.

 

This is  my script

Import-Csv "UsersGroups.csv" | ForEach-Object {

 $PrincName = $_."Logon Username" + "@info.rusu.lab"

 New-QADUser -Name $_."Display Name" `

 -ParentContainer $_."Container" `

 -SamAccountName $_."Logon Username" `

 -UserPassword "p@SSword" `

 -FirstName $_."Prenume" `

 -LastName $_."Nume" `

 -Description $_."Departament" `

 -UserPrincipalName $PrincName `

 -DisplayName $_."Display Name" ;`

 $groups= $_."Group" ,$_."Group2",$_."Group3",$_."Group4",$_."Group5"

 foreach ($grupe in $groups) {

 $grupuri=$grupe

 Add-QADGroupMember -identity $grupuri -Member $_."Logon Username";}`

  Set-QADUser -identity $_."Logon Username" `

 -UserMustChangePassword $true `

 }

 

Please support me to avoid this error.

Thank you


Viewing all articles
Browse latest Browse all 8583

Trending Articles