question

PrakashBesra-9385 avatar image
0 Votes"
PrakashBesra-9385 asked ·

Get-MessageTrace : The term 'Get-MessageTrace' is not recognized as the name of a cmdlet

     $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 user@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.




office-exchange-server-administrationwindows-server-powershell
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VaibhavChaudhari avatar image
0 Votes"
VaibhavChaudhari answered ·

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

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I have tried this also but still I am getting same error.

"Get-MessageTrace : The term 'Get-MessageTrace' 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."

And now it is giving error in PowerShell_ise and PowerShell window both



0 Votes 0 ·
michev avatar image
0 Votes"
michev answered ·

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://docs.microsoft.com/en-us/powershell/exchange/find-exchange-cmdlet-permissions?view=exchange-ps

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.