Avatar of Alex
Alex
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Sanity check on code please

Guys,

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


Thanks
Alex
Powershell

Avatar of undefined
Last Comment
Juan Ocasio

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Alex

ASKER
So splatting is very very similar to a hash group?
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.
Alex

ASKER
That's pretty. Very pretty. oBdA you need to let me buy you a few drinks.... :-)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Juan Ocasio

splatting creates a hash table of key/value pairs which you can chain onto a cmdlet.