Remote PowerShell Session Ends quickly - Access Denied after a few mins

What would be causing me to be able to Remote Powershell to my Exchange On-Prem servers, run a few commands, then after about 2-3 minutes get the

"Connecting to remote server exchcasserver.contoso.com failed with the following error message : Access is denied."

I am running the following to connect, we have 2016 and 2010 in the environment...

  Start-Transcript -Path C:\Transcripts\EXCH_OP_$(get-date -format 'MMddyyyy').txt -NoClobber -Append
  $Credentials = Import-Clixml C:\Scripts\Credentials\ExchOnPrem_credential.xml
  $SessionOpt = New-PSSessionOption -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true
  $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchcasserver.contoso.com/powershell/ -Credential $Credentials -SessionOption $SessionOpt
  Import-PSSession $Session -AllowClobber
  $FormatEnumerationLimit=-1

Help please... Thank you
Christian HansUndecided... Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITguy565Commented:
Try running your script under Powershell Admin.
ITguy565Commented:
or you can use the following in your script for credentials:
#Change Line 2 to 
   $Credentials = get-credential 

   #Change line 4 to 
   $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchcasserver.contoso.com/powershell/ -Credential $Credentials -SessionOption $SessionOpt

Open in new window



Make sure to run under admin powershell

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.