Link to home
Start Free TrialLog in
Avatar of Dallas Smetter
Dallas SmetterFlag for United States of America

asked on

Remote Exchange Shell Credentials

The following works when run from dos prompt  on the local machine.

PowerShell.exe -PSConsoleFile C:\Progra~1\Microsoft\Exchan~1\V15\Bin\exshell.psc1 -Command ". New-MailboxExportRequest -Mailbox gina_testuser -FilePath \\deo-netapp01\userarchive$\gina_testuser_RC.pst"

But when I attempt to run it remotely, I get Access Denied. How can I send my credentials along with the command?
Avatar of Dallas Smetter
Dallas Smetter
Flag of United States of America image

ASKER

This too works, but it prompts for a password

$ExchangeServer = "deo-ex1301.mrpm.sd42.ca"
$Cred = Get-Credential MRPM\s-idauto
$SessionParams =
@{
   ConfigurationName = 'Microsoft.Exchange'
   ConnectionURI     = "http://$ExchangeServer/powershell/"
   Authentication    = 'Kerberos'
   Credential = $Cred
}

$Session = New-PSSession @SessionParams

Invoke-command -ScriptBlock {New-MailboxExportRequest -Mailbox gina_testuser -FilePath \\deo-netapp01\userarchive$\aaa_gina_testuser_RC.pst} -Session $Session

Remove-PSSession $Session

How can I include the password ?
Avatar of Simon Butler (Sembee)
Version of Exchange would help here.
If Exchange 2010, then start PowerShell, not a command prompt.
Enter this command:

$UserCredential = Get-Credential

You will then get a prompt for a username and password. Remember to enter username as domain\username.

Then run this command:

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

That will connect you to the server with the credentials originally entered.

Finally connect to a session thus:
Import-PSSession $Session

You can then run whatever commands that you want.

With that particular command, remember to grant the account using the relevant permission. It isn't set by default to anyone.

Simon.
Import-PSSession $Session
Hi Simon this is Exchange 2013
ASKER CERTIFIED SOLUTION
Avatar of Simon Butler (Sembee)
Simon Butler (Sembee)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial