Link to home
Start Free TrialLog in
Avatar of dpdmembers
dpdmembersFlag for Barbados

asked on

How do I use Import-CSV and what are all the Parameters associated with it.

How do I import bulk users into Microsoft Exchange 2007 using both Import-Csv and Set-Contact together?
Avatar of 5g6tdcv4
5g6tdcv4
Flag of United States of America image

import-csv 2011.csv | foreach {New-mailbox -name $_.name -userprincipalname $_.userprincipalname -lastname $_.lname -initials $_.mi -firstname $_.fname  -alias $_.alias -displayname $_.display -org $_.grad-year -Password (ConvertTo-SecureString $_.Password -asplaintext -force) -resetpasswordonnextlogon $false -database "Mailbox Database 1736540864"}
save-as-2011.csv.xlsx
Avatar of dpdmembers

ASKER

I need to see how to use Set-Contact  with import-csv
Avatar of Mahmoud Sabry
what is the attributes that you want to set on for the contact?
Phone, Department, Fax, Title
then create CSV file as below
Contact,Phone, Department, Fax,Title

so that the first line is after the header is like the below line
email@comp.com,0020161234567,IT,01234567,"IT Manager"


then use the below cmdlet
import-csv Contacts.csv | foreach {Set-Contact -Identity $_.contact -Phone $_.phone -Department $_.department -Fax $_.fax  -Title $_.title }
Is this to done separately or can I use the following below?

import-csv 2011.csv | foreach {New-mailbox -name $_.name -userprincipalname $_.userprincipalname -lastname $_.lname -initials $_.mi -firstname $_.fname  -alias $_.alias -displayname $_.display -org $_.grad-year -Password (ConvertTo-SecureString $_.Password -asplaintext -force) -resetpasswordonnextlogon $true -database "Mailbox Database 1736540864" | Set-Contact -Identity $_.contact -Phone $_.phone -Department $_.department -Fax $_.fax  -Title $_.title}
the first part of the command "foreach {New-mailbox - .....etc" i used to create mailbox


and the second part of the command "| Set-Contact -Identity...... " is used to modify existing contact

you can't pipeline the commands the way u use as there are no relation between both

specify what do u need to exactly, create new mailboxes or modify existing contacts
Is the -Identity $_.contact  in Set-Contact equivalent to -userprincipalname $_.userprincipalname of New-mailbox? Other wise how does it know which contact to update?
Simply put.

Import-CSV reads a CSV file.
$Variable = Import-CSV "test.csv"

Open in new window

Will make it easier to manage and understand.

You've stored the entire table from test.csv in a variable and can access the information in it from powershell by calling the $CSV variable.

$Variable

Open in new window

and you will see the entire content of the CSV file.

the foreach-loop simply goes through each row or object from the previous command that you specify.

$_.Contact in a foreach loop is the value of the column "Contact" on the current Row. The part behind the "$_." is the value of the header for that column in your CSV-table.


ASKER CERTIFIED SOLUTION
Avatar of Mahmoud Sabry
Mahmoud Sabry
Flag of Egypt 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