PS to Office365
Windows PowerShell needs to be configured to run scripts, and by default, it isn't. You get the following error when you try to connect:
Files cannot be loaded because running scripts is disabled on this system. Provide a valid certificate with which to sign the files.
To enable Windows PowerShell to run signed scripts, run the following command in an elevated Windows PowerShell window (a Windows PowerShell window you open by selecting Run as administrator):
Set-ExecutionPolicy RemoteSigned
You need to configure this setting only once on your computer, not every time you connect.
- On your local computer, open Windows PowerShell and run the following command.
- $UserCredential = Get-Credential
- In the Windows PowerShell Credential Request dialog box, type your Office 365 user name and password, and then click OK.
- Run the following command.
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- Note If you are an Office 365 operated by 21Vianet customer in China, use the following value for the ConnectionUri parameter:
https://partner.outlook.cn/PowerShell
.
- Run the following command.
- Import-PSSession $Session
4. Disconnect when done
Get-PSSession | Where-Object {$_.ConfigurationName -eq "Microsoft.Exchange"} | Remove-PSSession
command:
- Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, IsArchiveMailbox, ItemCount, TotalItemSize | Export-CSV –Path “C:\Logs\ExchangeOnlineUsage.csv” (output the usage statistics to a CSV)
- Get-Mailbox -Filter {ArchiveStatus -Eq "None" -AND RecipientTypeDetails -eq "UserMailbox"} | Enable-Mailbox -Archive (Run the following command to enable the archive mailbox for all users in your organization (whose archive mailbox is currently not enabled)
- Search-Mailbox -Identity "John.Doe@tric.com" -SearchQuery ' Subject:"Invoice" ' -DeleteContent (delete all emails with Invoice in Subject )
- Search-Mailbox -Identity "John.Doe@tric.com" -SearchQuery {received:01/01/2018..01/01/2019} -DeleteContent (delete all emails inside date range (mm/dd/yyyy))
- Search-Mailbox can search only 10 000 results, so you will need to repeat the command if you have more that 10 000 records.
Note:
Be sure to disconnect the remote PowerShell session when you're finished. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you'll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the following command.
Get-PSSession
Remove-PSSession $Session (Remove-PSSession 1) (1 is the Session id)
to find out the ID of a user, to manually configure Outlook:
to list Status of pst import:
Get-mailboxImportRequest
to add O365 group to DistributionList ( possible only with PowerShell )
Add-DistributionGroupMember -Identity "Staff" -Member "JohnEvans@contoso.com"
Get-Mailbox -Identity user_name | select ExchangeGUID