Posts Tagged ‘Office365’

Scritps do Office 365 – parte 8: importando contatos externos para o Exchange Online

setembro 30, 2011


São Paulo (Chega por hoje) Esse post foi divulgado no blog do tim do Office 365. Trata sobre como importar contatos externos para o Exchange Online, usando um arquivo CVS.

Audience: Office 365/Exchange Online administrators

Author: Mark Johnson, Senior Technical Writer – Exchange Online

Do you have lots of existing business contacts that you want to include in the shared address book in Exchange Online? Or add your contacts as members of distribution groups, just like you can with users inside your company? If so, you can use Windows PowerShell and a CSV (Comma Separated Value) file to bulk import external contacts into Exchange Online. It’s a three-step process:

  1. Create a CSV file that contains information about the external contacts.
  2. Create the external contacts with PowerShell.
  3. Add information to the properties of each external contact with PowerShell.

Step1: Create a CSV file

Download the sample CSV file posted on the Downloads forum on the Office 365 community site. The sample file is actually a .txt file. So open it in Microsoft Excel, and save it as a CSV file. Use commas as the delimiters.

It includes sample data, which you can delete. But don’t delete the first row. It contains all of the properties for the external contacts. Create a row for each contact that you want to import to Exchange Online. Populate as many of the cells as possible. This information will be displayed in the shared address book for each contact.

However, the following parameters (which are the first four columns in the sample CSV file) are required to create an external contact and must be populated:

  • ExternalEmailAddress
  • Name
  • FirstName
  • LastName

When you’re finished preparing the CSV file, copy it to your desktop. Name it ExternalContacts.csv.

Step 2: Create the external contacts

In this step (and the next one), you have to use Windows PowerShell. To connect PowerShell to your Exchange Online organization, see Use Windows PowerShell in Exchange Online.

After you connect PowerShell to your cloud-based organization, run the following command to create the external contacts:

Import-Csv .\ExternalContacts.csv|%{New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}

Note: This command assumes that you are in the desktop directory in PowerShell. For example, C:\Users\Administrator\desktop.

To view the new external contacts, in the Exchange Control Panel, click Users & Groups > External Contacts > Refresh. They also appear in the shared address book in Outlook and Outlook Web App.

Step 3: Add information to the properties of the external contacts

After you run the command in step 2, the external contacts are created, but they don’t contain any of the contact or organization information, which is the information from the most of the cells in the CSV file).

Run the following commands to add the other properties from the CSV file to the external contacts you created:

$Contacts = Import-CSV .\externalcontacts.csv

$contacts | ForEach {Set-Contact $_.Name -StreetAddress $_.StreetAddress -City $_.City -StateorProvince $_.StateorProvince -PostalCode $_.PostalCode -Phone $_.Phone -MobilePhone $_.MobilePhone -Pager $_.Pager -HomePhone $_.HomePhone -Company $_.Company -Title $_.Title -OtherTelephone $_.OtherTelephone -Department $_.Department -Fax $_.Fax -Initials $_.Initials -Notes $_.Notes -Office $_.Office -Manager $_.Manager}

Don’t worry if you don’t have all the information populated in the CSV file. If it’s not there, it won’t be added.

Note: The Manager parameter can be problematic. If the cell is blank in the CSV file, you will get an error and none of the property information will be added to the contact. If you don’t need to specify a manager, then just delete –Manager $_.Manager from the previous PowerShell command.

That’s it. You can view the contact properties in the Exchange Control Panel. Users can see the contacts in the address book Outlook and Outlook Web App.

Adding more external contacts

You can repeats steps 1 through 3 to add new external contacts in Exchange Online. You or users in your company can just add a new row in the CSV file for the new contact. Then you can run the PowerShell commands from steps 2 and 3 to create and add information to the properties of the new contacts.

Note: When you run the command to create new contacts, you will get errors saying that the contacts that were created earlier already exist. But any new contact added to the CSV file is created.

Hide external contacts from the shared address book

Some companies may use external contacts only so they can be added as members of distribution groups. In this scenario, they may want to hide external contacts from the shared address book. Here’s how:

Hide a single external contact

Set-MailContact <external contact> -HiddenFromAddressListsEnabled $true

For example, to hide Franz Kohl from the shared address book:

Set-MailContact “Franz Kohl” -HiddenFromAddressListsEnabled $true

Hide all external contacts

Run the following command to hide all external contacts from the shared address book:

Get-Contact -ResultSize unlimited -Filter {(RecipientTypeDetails -eq ‘MailContact’)} | Set-MailContact -HiddenFromAddressListsEnabled $true

After you hide them, external contacts aren’t displayed in the shared address book, but you can still add them as members of a distribution group.



Carlos Monteiro.


Scritps do Office365 – parte1: Habilitando usuários contidos em um arquivo texto

julho 8, 2011

São Carlos (esse final de semana tem F1) Estou iniciando essa semana uma sequência de posts sobre scripts para administração e deploy do Office365 / BPOS, tanto em PowerShell quanto em VBS. Esses scritps foram gentilmente disponibilizados pelo grande profissional em Office365, o Cristiano Gonçalves.

Nesse primeiro script (em PowerShell), vamos abordar como habilitar os usuários contidos em um arquivo texto. O arquivo deverá ter um endereço SMTP por linha.

Salvem o código em um arquivo chamado BPOS_EnableUsers.ps1.

O uso do mesmo é simples: BPOS_EnableUsers [nome do arquivo txt]

Eis o código:

#This script enables users contained in a txt file in BPOS
#Must be used as BPOS_EnableUsers [filename]
#The file must have one smtp user address per line
#Author: Cristiano Gonçalves

#gets the name of the users file
$SourceFile = $args[0]

#gets the user list content
$userlist = Get-Content $SourceFile

#getting credentials
$targetcred = $host.ui.PromptForCredential(“Need credentials”, “Please enter TARGET credentials.”, “”, “NetBiosUserName”)

#getting the subscriptionid
$subscriptions = Get-MSOnlineSubscription -Credential $targetcred
foreach($subscription in $subscriptions)
$write = “Subscription ID: ” + $subscription.SubscriptionId + “`r`n”
foreach($type in $subscription.SubscriptionServiceTypes)
$write += ”                 ” + $type + “`r`n”
Write-Host $write

Write-Host ‘Enter the Subscription ID to assign:’ -foreground “yellow”
$subscriptionid = Read-Host
Write-Host “”

#creating the logfile
$date = Get-Date -format “ddMMyyyy”
$LogFile = $date + “_activation.txt”
remove-item $LogFile -ea SilentlyContinue

#function to generate passwords
$strChar =  “A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”I”,”J”,”K”,”L”,”M”,”N”,”O”,”P”,”Q”,”R”,”S”,”T”, “U”,”V”,”W”,”X”,”Y”,”Z”,”a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”
$strNum =  “1”,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″,”0″
$strComp =  “!”,”@”,”#”,”$”

#returns a complex password with 6 characters, two numbers and one special char
function generate-password
$pw = $null
for ($i=0; $i -lt 6; $i++)
$pw += get-random -InputObject $strChar
for ($i=0; $i -lt 2; $i++)
$pw += get-random -InputObject $strNum
$pw += get-random -InputObject $strComp
return $pw

#process the user list
foreach($user in $UserList)
$message = $(Get-Date -Format “ddMMyy hh:mm:ss”) +” Enabling User -> ” + $user
write-output $message
$passwd = generate-password
#Enables the online user with 25GB and for Trinidad & Tobago (NGC)
Enable-MSOnlineUser -Identity $user -Password $passwd -SubscriptionIDs $subscriptionid -UserLocation “TT” -MailboxQuotaSize 25GB -Credential $targetcred -Verbose
if($error.Count -ne 0)
$message = $(Get-Date -Format “ddMMyy hh:mm:ss”) + ” ERROR: User ” + $user + ” failed to enable.”
write-output $message | out-file -filePath $LogFile -append -noClobber
$message = $(Get-Date -Format “ddMMyy hh:mm:ss”) + ” ERROR:::: ” + $error[0].ToString()
write-output $message | out-file -filePath $LogFile -append -noClobber
$message = $(Get-Date -Format “ddMMyy hh:mm:ss”) + ” ENBLE: User ” + $user + ” enabled with passwd [” + $passwd + “].”
write-output $message | out-file -filePath $LogFile -append -noClobber


Carlos Monteiro.