Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Sanity check on code please


Can I please get a sanity check on this?

# Import AD Module             
Import-Module ActiveDirectory            
#enter CSV location
$users = Import-Csv -Path 'C:\temp\source.csv'         
# Loop through CSV and update users if the exist in CSV file            
foreach ($user in $users) {            
#Search in specified OU and Update existing attributes            
     Set-ADUser -identity $user -EmployeeID $user.EmployeeID -Department $User.'Department Name' -Company $user.Company -Office $user.Office -title $user.'Job Title'

Open in new window

Avatar of oBdA

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


So splatting is very very similar to a hash group?
Avatar of oBdA

It is a hash table, with the argument names as keys, and the value for the argument as value ([switch] types can be handled like bool).
The "splatting" part comes when passing it to the function/cmdlet: note the @ (instead of the $) in front of the variable name containing the hash table.
And as you can see above, you can combine splatting and regular arguments without problem.
splatting is usually easier to read/handle than line continuation with a near-invisible backtick.
Avatar of Alex


That's pretty. Very pretty. oBdA you need to let me buy you a few drinks.... :-)
splatting creates a hash table of key/value pairs which you can chain onto a cmdlet.