Can you try to run below code first and later run your PS code
Install-Module ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
$ROOT_PATH = "c:\folder"
$InputUserName = "xyz"
$OutputFile = "reportFile"
$cred = Get-Credential
# Connecting to Office 365 using admin credentials
Connect-MsolService -Credential $cred
# Creating a remote session to Exchange Online with admin credentials and importing cmdlets
$ExchangeOnlineSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication "Basic" -AllowRedirection
Write-host $ExchangeOnlineSession
Import-PSSession $ExchangeOnlineSession -DisableNameChecking -AllowClobber
Import-Module MSOnline
# Local date and time Zone below commented line instead of UTC
# UTC date and time Zone
$arr = @()
foreach($i in @(1,2,3))
{
$arr +=Get-MessageTrace -SenderAddress ******@contoso.com -page $i -pagesize 5000 -StartDate 03/11/2021 -EndDate 03/12/2021 | select 'RecipientAddress','Subject','Received','StartDate','EndDate','Index'
}
Remove-PSSession -Session $ExchangeOnlineSession
When I run this script on powershell_ise, I get result but when I run this script on powershell console then I am not getting any result and it gives error like
"Get-MessageTrace : The term 'Get-MessageTrace' is not recognized as the name of a cmdlet"
When I try to install to
"Install-Module ExchangeOnlineManagement -Repository PSGallery -AllowClobber -Force"
then it is giving error.
"Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable."
I tried this also : Set-PSRepository -Name "myInternalSource" -InstallationPolicy Trusted
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
but still i am gettin this error ""Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable."
please help me on this , i got stack in this situation.
Can you try to run below code first and later run your PS code
Install-Module ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
Please don't forget to Accept Answer and Up-vote if the response helped -- Vaibhav
You need permissions in order to be able to run the Get-MessageTrace cmdlet. To find out which permissions you need for a given cmdlet, follow the steps in this article: https://learn.microsoft.com/en-us/powershell/exchange/find-exchange-cmdlet-permissions?view=exchange-ps