Showing posts with label O365. Show all posts
Showing posts with label O365. Show all posts

Friday, March 15, 2024

[O365] Send email in O365 via Powershell

 

$Recipient = "contact@domain.com"

$Subject = "Hello, World!"

$Body = "This is the body of the email."

$credentials = Get-Credential

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $credentials.UserName -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $credentials


-----------------


Using saved/exported password:


# $credentials.Password | ConvertFrom-SecureString | out-file  L:\Downloads\senha.sec

$sen = Get-Content L:\Downloads\senha.sec | ConvertTo-SecureString

$us = "sender@mydomain.com"

$em = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $us,$sen

Send-MailMessage -To $Recipient -Subject $subject -Body $body -From $us -SmtpServer "smtp.office365.com" -Port 587 -UseSsl -Credential $em

Wednesday, November 1, 2023

[O365] Collect more than 1000 results in Message Trace

 $P = 1

$messages = $null

do

{

Write-Host “Message Trace – Page $P…”

$temp_Messages = Get-MessageTrace -startdate "09/12/2022 12:00:00 AM" -Enddate "09/12/2022 06:00:00 PM" -PageSize 1000 -Page $P

$P++

$Messages += $temp_Messages

}until ($temp_Messages -eq $null)


#display messages

$Messages.Count

$Messages

Monday, March 30, 2020

[O365] Export reports for quarantined messages



Get-QuarantineMessage | select ReceivedTime,SenderAddress,RecipientAddress,Subject,Type,SystemReleased,PolicyType,Expires | Export-CSV -NoTypeInformation “c:/reports.csv”

Monday, December 11, 2017

[O365] Change/remove groups and teams SMTP addresses




  • List all groups and their addresses:



Get-UnifiedGroup | fl alias,*primary*,*emailadd* 

  • Change primary SMTP

Get-UnifiedGroup group1 | Set-UnifiedGroup -PrimarySmtpAddress group1@newdomain.tech

  • Remove SMTP address from old domain:

Get-UnifiedGroup group1 | Set-UnifiedGroup -EmailAddresses @{remove="group1@olddomain.com"}

  • List group addresses:

Get-UnifiedGroup group1 | fl alias,*primary*,*emailadd* 

Friday, January 29, 2016

[O365] Recover messages deleted from Recoverable items folders


To verify the number of items:
Search-Mailbox "user@testtenant.com.br" -TargetMailbox "Discovery Search Mailbox" -TargetFolder "Recover1" -LogLevel Full -SearchDumpsterOnly -LogOnly

To copy the items to another user folder:
Search-Mailbox "user@testtenant.com.br" -TargetMailbox "user2@testtenant.com.br"  -TargetFolder "Recover1" -LogLevel Full -SearchDumpsterOnly

Monday, December 7, 2015

[O365] Migrating mailbox to cloud


$LiveCred = Get-Credential

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

Import-PSSession $Session

---------------

$OnPremCreds = Get-Credential

$MigrationEndpointOnPrem = New-MigrationEndpoint -ExchangeRemoteMove -Name OnpremEndpoint -Autodiscover -EmailAddress henwal@azurelab.dk -Credentials $OnPremCreds

In this example, we will migrate all users listed in a CSV file located on our system partition:

$OnboardingBatch = New-MigrationBatch -Name MigrationBatch1 -SourceEndpoint $MigrationEndpointOnprem.Identity -TargetDeliveryDomain azurelab.mail.onmicrosoft.com -CSVData ([System.IO.File]::ReadAllBytes("C:\MigrationBatch1.csv"))

Start-MigrationBatch -Identity $OnboardingBatch.Identity

[ADFS] Web Application Proxy fails with Error Code 0x8007520C


Cannot authenticate WAP in ADFS, after change main settings in either side

We will see the event ID 422 in Event Viewer on WAP server:



Additional Data:

Trust Certificate Thumbprint:
090D9BB9B0471127EDE9CEA66C2AE79223E349FC

Status Code:
Unauthorized

Exception details:
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()

at Microsoft.IdentityServer.Management.Proxy.StsConfigurationProvider.GetStsProxyConfiguration

In ADFS server, we can see event ID 276:

The federation server proxy was not able to authenticate to the Federation Service.
User Action
Ensure that the proxy is trusted by the Federation Service. To do this, log on to the proxy computer with the host name that is identified in the certificate subject name and re-establish trust between the proxy and the Federation Service using the Install-WebApplicationProxy cmdlet.
Additional Data
Certificate details:
Subject Name:
<null>
Thumbprint:
<null>
NotBefore Time:
<null>
NotAfter Time:
<null>

We need to check the certificate: dir Cert:\LocalMachine\My

Using the thumbprint of the certificate that I want the WAP to use, I am prompted for the service account credentials when I use the following command.
Install-WebApplicationProxy -CertificateThumbprint ’36E56E2F7ECE610C330EE370125454BBE5735A74′ -FederationServiceName ‘adfs.techrede.net’

Saturday, September 5, 2015

[O365] Reset O365 password



Microsoft Online Services Reset your password

[O365] Connect to Office 365





Step 1: Start Windows PowerShell as an administrator

Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned

Step 2: Create a Windows PowerShell credentials object

$credential = Get-Credential

Step 3: Connect to Office 365

Import-Module MsOnline
Connect-MsolService -Credential $credential

Step 4: Connect to Exchange Online

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

Import-PSSession $exchangeSession

Obs: IF SSL ERROR

$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig

$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -AllowRedirection -SessionOption $proxysettings


Step 5: Connect to SharePoint Online

Import-Module Microsoft.Online.SharePoint.PowerShell
Connect-SPOService -Url https://litwareinc-admin.sharepoint.com -credential $credential


Step 6: Connect to Lync Online

Import-Module LyncOnlineConnector
$lyncSession = New-CsOnlineSession -Credential $credential
Import-PSSession $lyncSession





[O365] Changing DirSync schedule




The default dirsync period between On-premise and Office 365 is 3 hours. This for many people is too long, especially if you are testing.

If you wanted to change the default sync period then firstly navigate to the Windows Azure Active Directory Sync directory on the member server where the Directory Sync tool is installed. Older version (i.e. pre Azure) the directory will be called Microsoft Online Directory Sync.

In this folder open up the file Microsoft.Online.DirSync.Scheduler.exe.config file.

Adjust the setting <add key=”SyncTimeInterval” value=”3:0:0″ />

For example if you wanted to bring this down to 10 minutes then change this line to the following. <add key=”SyncTimeInterval” value=”0:10:0″ />

Close and Save the file and then restart the Windows Azure Active Directory Sync Service


Change the Azure Active Directory Sync Schedule



[O365] Configure filtering for DirSync




Configure filtering for directory synchronization




1.      Uncheck the Synchronize directories now from the DirSync Finish window and click Next.

2.      From your DirSync Server navigate to <Drive>\Program Files\Microsoft Online Directory Sync\SYNCBUS\Synchronization Service\UIShell

3.      Double click on miisclient.exe

4.      In Identity Manager, click Management Agents, and then double-click SourceAD.

5.      Click Configure Directory Partitions, and then click Containers

6.      When prompted, enter your domain credentials for the on-premises Active Directory forest.

7.        In the Select Containers dialog box, clear the OUs that you want skip from syncing to Office365, and then click OK.

8.        Click OK on the SourceAD Properties page.

9.        Perform a full sync: on the Management Agent tab, right-click SourceAD, click Run, click Full Import Full Sync, and then click OK.

10.        You can also force run DirSync using the following PowerShell command.

Start-OnlineCoexistenceSync -FullSync

11.        To confirm the sync job, open your event log and look for Event ID’s 1 & 2.

i.        Event ID 1 says If configuration Import started
ii.        Event ID 2 says if configuration Import has completed.


Note:

Filtering configurations applied to your directory synchronization instance aren’t saved when you install or upgrade to a newer version. If you are upgrading to a newer version of directory synchronization, you must re-apply filtering configurations after you upgrade, but before you run the first synchronization cycle.

[O365] Purge Deleted Users and Mailboxes from Office 365




Single­User Deletion:

Remove-MsolUser -UserPrincipalName username@mydomain.com
Get-MsolUser -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

Bulk User Deletion:

Get-MsolUser -MaxResults 30 -ReturnDeletedUsers | Remove-MsolUser -RemoveFromRecycleBin -Force

[O365] DirSync attributes




[O365] License Information




Get-MsolUser -UserPrincipalName user@domain.com|select -ExpandProperty Licenses |select -ExpandProperty ServiceStatus


Getting all Licensed Office 365 users with PowerShell

[O365] Office 365 Plan Options





Service
Office 365 Business Essentials
Office 365 Business Premium
Office 365 Enterprise E1
Office 365 Education E1
Office 365 Government E1
Office 365 Enterprise E3
Office 365 Education E3
Office 365 Government E3
Office 365 Enterprise E4
Office 365 Education E4
Office 365 Government E4
Office 365 Enterprise K1
Office 365 Government K1
Office 365 Platform
Yes
Yes
Yes
Yes
Yes
Yes
Exchange Online
Yes
Yes
Yes
Yes
Yes
Yes
SharePoint Online
Yes
Yes
Yes
Yes
Yes
Yes
OneDrive for Business
Yes
Yes
Yes
Yes
Yes
No
Lync Online
Yes
Yes
Yes
Yes
Yes
No
Office Online
Yes
Yes
Yes
Yes
Yes
Yes
Office 365 ProPlus
No
No
No
Yes
Yes
No
Office 365 Business
No
Yes
No
No
No
No
Project Online
No1
No1
No1
No1
No1
No1
Yammer Enterprise
Yes
Yes
Yes2
Yes2
Yes2
Yes2
Azure Rights Management (RMS)
No3
No3
No3
Yes
Yes
No3

[O365] Modules



Microsoft Online Services Sign-In Assistant for IT Professionals RTW



Azure Active Directory Module for Windows PowerShell (64-bit version)



Windows PowerShell Module for Lync Online



SharePoint Online Management Shell