Category Archives: 365 Powershell

Adding Contacts to O365 with CSV files – KB10392210

KB10392210

Adding Contacts to Office 365 Exchange server

Customer requesting external contact to be added to the Exchange server and Setting up Distrabution groups

Download the Follow File and have the customer fill out the information for the Contacts needing to be added

ContactsCSV

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 are required to create an external contact and must be populated:

•ExternalEmailAddress
•Name
•FirstName
•LastName
•OtherTelephone
•Manage
After the ontact has returned the needed file you can start to setup the new Distribution groups in O365

The Follow is the commands used to log in to the Servers PowerShell interface

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

first command will only create the Contact without extended information

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

They command will update the Contacts on the system with the extended information

$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}

Used to add the new contacts to the Distribution lists

you will need to remove all but the users names from the CSV file and rename the Tab to Members

Import-CSV <path> | ForEach {Add-DistributionGroupMember -Identity <Distribution Group Name> -Member $_.members}

 

Office 365 Get last login per user account – KB10391232

KB10391232

This command will give you a .cvs with user names and the last date and time of login. See KB1039659 to get started.

After getting into the server run this command. There is a catch: you need to change the file path or on the root of C you could just create a folder called ‘ out ‘

 

Get-mailbox -resultsize unlimited| Get-MailboxStatistics | select displayname, lastlogontime | Export-Csv C:outLastLogin.csv

Office 365 Get list of all users on the server KB1039751

KB1039751

Start by referring to KB1039659 to get connected to the O365 server

the command is simple:

get-user | Export-Csv C:users%username%DesktopLicensedUsers.csv

the file path and name is arbitrary so if you want to change it that would be fine otherwise this should create a .cvs file on your desktop called LicensedUsers.csv

You will have to look at the .cvs and delete the colums that are not needed if you are sending it to someone

Pro tip: Ctrl + – (minus sign) will allow you to delete rows 

Office 365 Powershell Add to whitelist KB1039665

KB1039665

In this article we will cover how to whitelist via Powershell in several ways. Assuming that you already have logged into the server using Powershell   (see  http://www.cpumd.com/KB1039659 )

To white list a domain for every user

Get-Mailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains “domain.com”

To white list a specific email address for every user

Get-Mailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains “user@domain.com”

To white list a domain for a specific user

Set-MailboxJunkEmailConfiguration -Identity youruser@yourdomain.com -TrustedSendersAndDomains “domain.com”

To white list a specific email address for a specific user

Set-MailboxJunkEmailConfiguration -Identity youruser@yourdomain.com -BlockedSendersAndDomains “user@domain.com”

Office 365 Powershell into a server KB1039659

In this article I will cover the basic way to connect to a 365 server with Powershell.

Right click on Powershell and run as admin

c:~>  Set-ExecutionPolicy RemoteSigned ( normal powershell only )
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [N] No [S] Suspend [?] Help (default is “Y”): Yes

You must answer YES !!!!!!

c:~>   $LiveCred = Get-Credential

then enter the admin creds for OWA

o365 logon 1

This is the next command:

c:~>   $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $LiveCred -Authentication Basic –AllowRedirection

Then:

c:~>  Import-PSSession $Session

And you should end up with this, if so you are good to run commands now O365 logon 2

 

pwillette 2/18/15

 

Office 365 blacklist address / domain KB1039657

KB1039657

Situation: Client is receiving spam email from a cretin email address in Office 365

Solution: Use Office 365 Powershell to block the email address

To blacklist a domain for every user

Get-Mailbox | Set-MailboxJunkEmailConfiguration -BlockedSendersAndDomains “domain.com”

To blacklist a domain for a specific user

Set-MailboxJunkEmailConfiguration -Identity youruser@yourdomain.com -BlockedSendersAndDomains “domain.com”

To blacklist a specific email address for every user

Get-Mailbox | Set-MailboxJunkEmailConfiguration -BlockedSendersAndDomains “user@domain.com”

To blacklist a specific email address for a specific user

Set-MailboxJunkEmailConfiguration -Identity youruser@yourdomain.com -BlockedSendersAndDomains “user@domain.com”