We help IT Professionals succeed at work.

Sanity check on code please

Alex
Alex asked
on
66 Views
1 Endorsement
Last Modified: 2018-09-25
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
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
So splatting is very very similar to a hash group?
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
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.
AlexA lack of information provides a lack of a decent solution.
CERTIFIED EXPERT

Author

Commented:
That's pretty. Very pretty. oBdA you need to let me buy you a few drinks.... :-)
Juan OcasioContinuous Process Improvement Lead
CERTIFIED EXPERT

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