Monday, 20 September 2021

How to delete all content-emails from a mailbox and make it blank in exchange server 2016

Some time you may have a test mailbox and it may have some unwanted emails and you may need to delete all the emails permanently.

 You can use a simple command as below in Exchange PowerShell

Search-Mailbox -Identity "nawaz" -DeleteContent

Please note that the emails will be deleted permanently and you would not able to recover even from the recoverable items.


Resolved: The term 'New-ComplianceSearch' is not recognized as the name of a cmdlet

 Today i was trying to search and delete an email from user's mailboxes in Exchange online/Office 365.

My steps were as below.

1: Connect-EXOPSSession -UserPrincipalName myadmin@mydomain.com

2:

$Search=New-ComplianceSearch -Name "Remove Phishing Message" -ExchangeLocation All -ContentMatchQuery '(Received:4/13/2016..4/14/2016) AND (Subject:"Action required")' Start-ComplianceSearch -Identity $Search.Identity

But were getting the following error

New-ComplianceSearch : The term 'New-ComplianceSearch' is not recognized as the name of a cmdlet, function, script      file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct   and try again.          

Solution:

Run the following command to connect to "Security & Compliance Center PowerShell"

Connect-IPPSSession -UserPrincipalName khan.nawaz@pt.net.com

and after that is was able to run the New-ComplianceSearch command.

As per TechNet article this command is used to connect to Security & Compliance Center PowerShell or standalone Exchange Online Protection PowerShell using modern authentication. The cmdlet works for MFA or non-MFA enabled accounts.

For further detail:

Connect-IPPSSession (ExchangePowerShell) | Microsoft Docs

and 

Search for and delete email messages in your organization - Microsoft 365 Compliance | Microsoft Docs 

                                               

Thursday, 16 September 2021

How to migrate Skype for business users from Skype for business online to skype for business on premise with powershell

Some time you need to offboard your skype users from Skype for business online (Office 365) to your Skype for business on premise infrastructure. you can use the Skype for business Control panel or the PowerShell. To use the PowerShell you can follow the following steps. make sure that your FE server have internet access or access at least to Office 365, and also make sure that you have the required privileges to both Office 365 and on your on premise Skype for business environment.

Then Login to your FE server and open the "Skype for business Server management shell" with Run as administrator privileges. 

Then store your credentials with the following command in $cred variable.

$cred=Get-Credential 

(Note: you should use Global Admin or any other admin users with required rights and the user should be like in admin@yourdomain.onmicrosoft.com format )

then use the following command to move for example the user Abc@domain.com.


Move-CsUser -Identity Abc@domain.com -Target SFB15FEPool.domain.com -HostedMigrationOverrideUrl  https://adminxa.online.lync.com/HostedMigration/hostedmigrationService.svc -Credential $cred  -Confirm:$False 


or you can store the URL in a variable and then use following command.

$url="https://admin1a.online.lync.com/HostedMigration/hostedmigrationService.svc"

Move-CsUser -Identity username@contoso.com -Target pool.corp.contoso.com -Credential $cred -HostedMigrationOverrideUrl $url

(Note: store your HostedMigrationOverrideUrl in $url, which you can find from office 365 and may be some thing like in below format. (only the XA may be different for each tenant)

$url=https://adminXA.online.lync.com/HostedMigration/hostedmigrationService.svc)

For further detail look into the following link.

https://docs.microsoft.com/en-us/previous-versions/office/lync-server-2013/lync-server-2013-move-users-to-lync-online?redirectedfrom=MSDN 

Saturday, 10 July 2021

Resolved: The subscription file failed to load for the following reason: The direct trust certificate of the subscribed Edge Transport server with thumbprint is a duplicate of the certificate of one of the HubTransport servers. Sharing the same certificate between Edge and Hub Transport

Issue:

Due to some issues, i had to re subscribe the edge server.

After creating the edge subscription file on the edge server with the following command.

New-EdgeSubscription –FileName “c:\EdgeSubFile.xml”

then copied the file "EdgeSubFile" to one mailbox server. and tried the following command.

New-EdgeSubscription -FileData ([byte[]]$(Get-Content -Path "c:\EdgeSubFile.xml" -Encoding Byte -ReadCount 0)) -Site "sitename"


 Getting the following Error:

The subscription file failed to load for the following reason: The direct trust certificate of the subscribed Edge Transport server with thumbprint

<Thumprint> is a duplicate of the certificate of one of the HubTransport servers. Sharing the same certificate between Edge and Hub Transport

servers is not allowed.

    + CategoryInfo          : InvalidOperation: (:) [New-EdgeSubscription], InvalidOperationException

Solution:

as mentioned in the error, the issue was with the SSL certificate, So after some searching on some forums, tried the following steps and the issue was resolved/successfully subscribed the edge.

On the edge server

  1. copy/backup of the currently used SSL certificate for SMTP services.
  2. delete that SSL
  3. import another SSL certificate to the personal store of that edge
  4. Enable that SSL for SMTP services
  5. i.e (Enable-ExchangeCertificate -Thumbprint <34434kklkjlkjkdkfjk> -Services SMTP) 
  6. restart the "Microsoft Exchange ADAM" service
  7. create the subscription file again (New-EdgeSubscription –FileName “c:\EdgeSubFile1.xml”)
  8. copy the file maibox server
on mailbox server
in exchange management shell use the following command for new sub subscription.
New-EdgeSubscription -FileData ([byte[]]$(Get-Content -Path "c:\EdgeSubFile.xml" -Encoding Byte -ReadCount 0)) -Site "sitename"
was successfully able to resubscribe
On the edge server

  1. delete the SSL certificate which we imported and assigned to SMTP services before for edge subscription
  2. So open mmc and delete that certificate.
  3. import the valid certificate which we want to use for SMTP services 
  4. enable that new certificate for smtp services 
  5. i.e (Enable-ExchangeCertificate -Thumbprint <34fdsf434kklkfdfjlkjkdkfjk> -Services SMTP)
  6. restart the "Microsoft Exchange ADAM" service on the edge server
on the mailbox server 
restart the Microsoft Exchange Transport and Microsoft Exchange EdgeSync services
Test the subscription with the following power shell commands 

Start-EdgeSynchronization -ForceUpdateCookie -ForceFullSync
should have result as success or inprogress like as below.
Result         : Success
Type           : Configuration
or 
Result         : InProgress
Type           : Recipients

Test-EdgeSynchronization
should have syncstatus Normal, like as below.
RunspaceId                  : 58fdsfad-dfds-4123-adf1-39a802dcd2bd
SyncStatus                  : Normal
UtcNow                      : 7/10/2021 3:55:35 PM

check mailflow/Queue
with get-Queue poweshell command



Wednesday, 30 June 2021

How To connect Exchange online through powershell if MFA is enabled

 You have to first download "Microsoft Exchange Online Power shell Module" from your exchange admin center portal (https://outlook.office.com/ecp/



then you have to open the "Microsoft Exchange Online Power shell Module" and you should get the window like below.


Then you have to use the command (Connect-EXOPSSession -UserPrincipalName AdminUser@domain.com) in Microsoft Exchange Online Power shell Module.



then it should pop up for the credentials and also for the second factor authentication.


Friday, 25 June 2021

Get Office 365 users with a specific license

First we have to connect MSOLService through powershell.

Connect-MsolService

Then get the list of available licenses with the following command.

Get-MsolAccountSku

then we can use the following command to Get the users with a specific license

Get-MsolUser -MaxResults 200000 | Where-Object {($_.licenses).AccountSkuId -match "p:ems"} >c:\pathc\EMSUsers.CSV

Wednesday, 12 May 2021

How to Search Admin Audit log in Office 365 against a mailbox

 Go to 

Audit log search - Security & Compliance (office.com)

on the right side Select Search ---> Audit log Search---->in Search Activities "Show activities for all activities"

set Start and End dates

in Users box enter the mailbox/email address on which you want the activities performed.

in file, folder, or Site you may enter required details, even may be the subject of the email.

then it may take some time to complete the query  and then you may download the result of the search in excel sheet or can view in the same window here.

it will show all the activities performed on the mailbox.