dpdmembers
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?
ASKER
I need to see how to use Set-Contact with import-csv
what is the attributes that you want to set on for the contact?
ASKER
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,00201612345 67,IT,0123 4567,"IT Manager"
then use the below cmdlet
import-csv Contacts.csv | foreach {Set-Contact -Identity $_.contact -Phone $_.phone -Department $_.department -Fax $_.fax -Title $_.title }
Contact,Phone, Department, Fax,Title
so that the first line is after the header is like the below line
email@comp.com,00201612345
then use the below cmdlet
import-csv Contacts.csv | foreach {Set-Contact -Identity $_.contact -Phone $_.phone -Department $_.department -Fax $_.fax -Title $_.title }
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}
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
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
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?
Simply put.
Import-CSV reads a CSV file.
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.
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.
Import-CSV reads a CSV file.
$Variable = Import-CSV "test.csv"
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
save-as-2011.csv.xlsx