Avatar of dpdmembers
dpdmembers
Flag 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?
PowershellExchange

Avatar of undefined
Last Comment
Mahmoud Sabry

8/22/2022 - Mon
5g6tdcv4

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
deviprasadg

dpdmembers

ASKER
I need to see how to use Set-Contact  with import-csv
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Mahmoud Sabry

what is the attributes that you want to set on for the contact?
dpdmembers

ASKER
Phone, Department, Fax, Title
Mahmoud Sabry

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 }
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
dpdmembers

ASKER
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}
Mahmoud Sabry

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
dpdmembers

ASKER
Is the -Identity $_.contact  in Set-Contact equivalent to -userprincipalname $_.userprincipalname of New-mailbox? Other wise how does it know which contact to update?
Your help has saved me hundreds of hours of internet surfing.
fblack61
stefor

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
Mahmoud Sabry

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.