Prevent Powershell ForEach from Adding Superfluous Quotes -
i have colon-delimited csv so,
mailbox:users acmecorp:("jsmith","trex") xyzcorp:("sjobs","bfranklin")
it added variable:
$file = import-csv file.csv -delimiter :
now, work it:
foreach ($record in $file) { $record.users | % { get-aduser $_ } }
write-host
in foreach loop reports $record.users
("jsmith","trex")
however, get-aduser
(or other cmdlets) complains cannot find object identity '("jsmith","trex")'
.
how prevent foreach adding single quotes parameter?
i've tried users "sjobs","bfranklin"
import-csv strips double quotes off of sjobs
or better, how pass list of users foreach?
powershell version 4
the quotes not being added ps. right there in file. here snippet give start in right direction:
$file = import-csv file.csv -delimiter ':' foreach($row in $file){ foreach($user in $row.users.split(',')){ get-aduser ($user.replace('(','').replace('"','').replace(')','')) } }
Comments
Post a Comment