简体   繁体   中英

What [else] does this PowerShell Command? How could I reproduce it in Java?

I want to create a web application where employees could manage their email-forwarding settings.

In the past, this happened via some PowerShell scripts. For example, setting email forward with copy:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[server] -Authentication Kerberos
Import-PSSession $Session
Set-Mailbox -Identity "{USERNAME}" -DeliverToMailboxAndForward $true -ForwardingAddress "{EMAIL}"

I set the redirection and watched the Active Directory for changes. It set the parameter altRecipient of the original recipient to the DN of the new and the parameter altRecipientBL of the new recipient to the DN of the old. I tried to reproduce these parameters with JND functionalities, but it doesn't redirect the mails. So there must be more what this PowerShell Command does, maybe changing the settings of the ExchangeServer.

How could I reproduce following functionality in Java preferably without using the PowerShell?

  • check forwarding status
  • remove forwarding
  • set forwarding with copy
  • set forwarding without copy

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[server] -Authentication Kerberos :Creates a new remote session (via WSMAN) to the exchange server.

Import-PSSession $Session : Is used to import the remote Exchange cmdlets to your local machine. If you would not call Import-PSSession , Set-MailBox -cmdlet of the next line would not be available on your local machine:

Set-Mailbox -Identity "{USERNAME}" -DeliverToMailboxAndForward $true -ForwardingAddress "{EMAIL}"

From microsoft :

The Import-PSSession cmdlet imports commands , such as cmdlets, functions, and aliases, from a PSSession on a local or remote computer into the current session. You can import any command that the Get-Command cmdlet can find in the PSSession. ...

Your question:

How could I reproduce following functionality in Java preferably without using the PowerShell?

Well you've to use kind of Java remoting mechanism towards Exchange server. On the Exchange server there needs to be some endpoint that is able to call the PowerShell command.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM