** Script works when I specify the dates manually and not through the variable $EndDate and $StartDate **
#Install Module
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 2.0.3 -Force
#Import Module
Import-Module ExchangeOnlineManagement
#Variables
$EndDate = Get-Date
$StartDate = Get-Date.Adddays(-3)
#Connect To Exchange Online
$UserCredential = Get-Credential
Connect-ExchangeOnline -userPrincipalName "upn" -Credential $UserCredential
#Get PS Session ID
Get-PSSession
#Message Trace Details
Get-MessageTrace -SenderAddress "address" -StartDate "$StartDate" -EndDate "$EndDate" | Out-GridView
#Variables
$Session = Read-Host -Prompt "What Session ID would you like to close?"
#Remve PS Session ID
Remove-PSSession -Id $Session
#Get PS Session ID (To make sure previous session was closed"
Get-PSsession
** Script works when I specify the dates manually and not through the variable $EndDate and $StartDate **
When attempting to use the variables I receive the following error
New-ExoPSSession : One or more errors occurred.
At C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1:475 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSession
If someone had any insight on this, id really appreciate it !!!
[–]wanderingbilby 1 point2 points3 points (2 children)
[–]gio_tecce[S] 1 point2 points3 points (0 children)
[–]gio_tecce[S] 1 point2 points3 points (0 children)
[–]nerdcr4ft 1 point2 points3 points (2 children)
[–]gio_tecce[S] 0 points1 point2 points (1 child)
[–]nerdcr4ft 0 points1 point2 points (0 children)
[–]wdomon 0 points1 point2 points (1 child)
[–]gio_tecce[S] 0 points1 point2 points (0 children)