Link to home
Start Free TrialLog in
Avatar of Jacob Durham
Jacob DurhamFlag for United States of America

asked on

CSV input to Active Directory

I'm working on a script to update AD based on a CSV from Human Resources. It's working for the most part but I need help with 2 things.

Is it possible to get a summary of the missing/not found accounts at the end of the script? And then I'm confused on how I can make the -manager not change if the account is not found?



$userbase = import-csv \\caph-fs2\home\jacobd\desktop\userbase.csv

foreach ($name in $userbase)

  {
    $First  = $Name.FirstName
    $last   = $Name.LastName
       $user=Get-ADUser -Filter "GivenName -eq '$First' -and Surname -like '$last'" 
        if( $User )
     {

        Write-host $name.firstname $name.lastname $name.department $name.division $name.title
       ##  $User | set-aduser -department $name.department -division $name.division -title $name.title -reports {get-aduser -filter {CN -like "$name.manager"}}
     }
     else
     {
     New-Object PSObject -Property @{
             GivenName      = $First
             Surname        = $last
             SamAccountName = 'MISSING ACCOUNT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
             }
     }
 
 }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dustin Saunders
Dustin Saunders
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial