Launch Scheduled Task to Query Remote Exchange Server

Hi,

This is my first time here. I need some help. I am collecting information from Distribution Lists. The exchange server is configured as default 30 days for retention. I have the tools installed on a remote jump server. I can open powershell and connect to the remote exchange server. I can run the ps1 successfully. The information is exported to a .csv. I would like to schedule a task. I don’t know how to add the connection commands to the existing ps1 so that I would not be prompted to enter my username and password each time the task runs. How do I automate that set of commands to automatically connect to the remote exchange server when the task runs?

So currently, on the jump box, I open powershell as administrator, and I type:
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://LMNOPServer/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking

Then I launch the script and it collects the information I need. But when I run a scheduled task, from the jump box, then I think that PowerShell is not authenticating to the remote server?

I have never worked with Exchange but typically you would create a credential object and then use it as argument for the Credential parameter.

$Username = 'domain\yourusername'
$Password = 'YourPass' | ConvertTo-SecureString -AsPlainText -Force
$UserCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$Password

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://LMNOPServer/PowerShell/ -Authentication Kerberos -Credential $UserCredential
Import-PSSession $Session -DisableNameChecking

Thanks ferc.

Is the credential object a different file with a ps1 extension?

No, just use the code from my previous post and see if it works.

Thanks ferc. I understand! Thanks a lot for helping me.