Microsoft Exchange session best practice

Microsoft Exchange session best practice

avatar
(anonymous user)

Simple question, really: Is there a recommended method by which to run queries against mailbox servers, such as the $session being shared across endpoints etc.?

All Comments (5)

avatar
(anonymous user)

Hello @AnonymousUser I have not personally designed a dashboard to connect to a mailserver as of yet…However I do have several scheduled tasks on my computer which gather information from certain mailboxes and output it to a CSV…I could then load that CSV into a dashboard…so as the exchange commands need importing from a session, and you then need to close the session, just thinking this could cause lag on your dashboard…so depending what you want to display is doing a CSV option a route that you would use? If so you could then load into a grid and display the information that way, or a chart.

$Username = "YOUR-DOMAIN\Administrator"
$SecurePassword = Get-Content C:\Path-To-EncryptedPassword\password.txt | ConvertTo-SecureString
$UserCredential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$SecurePassword
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://YOUR-MAIL-SERVERNAME/PowerShell/ -Credential $UserCredential -Authentication Kerberos
Import-PSSession $Session
# run your exchange commands commands
Remove-PSSession $Session


Is how I would go about connecting to an Exchange server, I have this as ascheduled job and it works without fail. I personally would use results from a scheduled job if you need to run Exchange cmdlets in your dashboard?

avatar
(anonymous user)

Cheers for the reply.

In the end I went with the Exchange pssnapin after installing the exchange tools.

I created a function that adds the snapin and then performs the required queries. For my case I then call that function from a new-udendpoint that runs on a schedule, saving the results to a $cache:variable.

It works great, and avoids the issues with making multiple remote session calls (though I suppose that would be mostly mitigated with a scheduled endpoint call, anyway).

avatar
(anonymous user)
Exchange pssnapin

@AnonymousUser: What exchange are you running? I’m running in 2013.
@AnonymousUser I have been unable to follow the code above in Powershell Universal Dashboard. However, normal PowerShell works wonders.

Here is the error message I get using code above with my company information:
2929321d0fb396618fd803041bef38099957b725

2929321d0fb396618fd803041bef38099957b725.png

avatar
(anonymous user)

Sorry for the late reply!

Exchange 2016. You need to install the exchange tools on the dashboard box.

avatar
(anonymous user)

Are you willing to share your code? I am trying to poll message tracking logs and im struggling to get any output when connecting to the servers.

Enter-PSSESSION gets stuck and it states on their it they do not support it.Invoke-command doesnt work either.