0 votes

Good Day,

I'm just looking for quick assistance in running a couple commands in a custom command. These are Exchange Management Shell commands that would need to be called from within an existing Custom command that already converts the user to a shared mailbox. We also require the following commands to run

Set-Mailbox -Identity $mailbox.alias -MessageCopyForSendOnBehalfEnabled $true Set-Mailbox -Identity $mailbox.alias -MessageCopyForSentAsEnabled $true

I've seen the following article on how to access emc from a powershell script and would like to confirm there is no simpler method

https://www.adaxes.com/script-repository/connect-to-exchange-with-powershell-s506.htm

We use an on-prem exchange server, please let me know if you require any more information

by (700 points)

1 Answer

0 votes
by (14.9k points)

Hello,

Unfortunately, there is currently no other possibility to manage the MessageCopyForSendOnBehalfEnabled and MessageCopyForSentAsEnabled mailbox properties in Adaxes except using a script. However, thank you for the suggestion, we passed it to the corresponding department for consideration. To connect to your on-premises Exchange, use the Exchange On-Premises script from the repository article you mentioned. Should you have any issues writing the script, please, provide us with all the possible details regarding the required behavior along with live examples and we will help you.

0

Hello,

Can you verify then that the below is free of syntax errors that I may have missed? Also I assume this will apply against the mailbox being accessed via the custom command:

$exchangeServer = "servername.domain.com" # TODO: modify me

{
    # Connect to Exchange server
    $session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
    Import-PSSession -session $session -CommandName "Set-Mailbox"

    # Set commands against the mailbox
Set-Mailbox -Identity $mailbox.alias -MessageCopyForSendOnBehalfEnabled $true
Set-Mailbox -Identity $mailbox.alias -MessageCopyForSentAsEnabled $true
}

{
    # Close the remote session and release resources
    if ($session) { Remove-PSSession -Session $session}
0

Hello,

In the provided script, the try and finally blocks are missing. The Set-Mailbox cmdlet is executed on the mailbox of the user the custom command is running on. Hence, there is no need to use the $mailbox variable. The %distinguishedName% value reference can be used instead. Also, there is no need to execute the Set-Mailbox cmdlet twice, both parameters can be set in a single call of the cmdlet. Please, find the updated script below.

$exchangeServer = "servername.domain.com" # TODO: modify me

try
{
    # Connect to Exchange server
    $session = New-PSSession -connectionURI "http://$exchangeServer/powershell" -ConfigurationName Microsoft.Exchange
    Import-PSSession -session $session -CommandName "Set-Mailbox"

    # Set commands against the mailbox
    Set-Mailbox -Identity "%distinguishedName%" -MessageCopyForSendOnBehalfEnabled $true -MessageCopyForSentAsEnabled $true
}
finally
{
    # Close the remote session and release resources
    if ($session) { Remove-PSSession -Session $session}
}

Related questions

0 votes
1 answer

I asked this question last year, but have just dealt with running the commands manually since as I was unable to work out a solution. https://www.adaxes.com/questions/10506 ... desktop support not Azure Magician and do not know what API's teams falls under.

asked Apr 1, 2022 by TheLexicon (200 points)
0 votes
1 answer

How to I block users from running custom commands? i can't locate this functionality. :?:

asked Sep 2, 2011 by BeaconlightBoy (80 points)
0 votes
1 answer

Is there a way to have a Scheduled Task with 4 different condition? I want to create a scheduled task start every Monday and the condition see: The next Saturday of the week ... of the week is the fifth of the month then no action Thanks in advance, Simone

asked Jan 18, 2022 by Simone.Vailati (430 points)
0 votes
1 answer

An environment that we wish to use Adaxes on is completely isolated with no access to the internet. Things can be downloaded from the internet and then moved ... offline environment? Can Adaxes be patched and upgraded in an offline environment? Many Thanks

asked Apr 13, 2020 by antondubek (440 points)
0 votes
0 answers

I'm trying to setup a quick automations to drop a notification into a Micrsoft Teams feed using their Webhook integration. I've managed to make Webhooks work ... -body $body -ContentType 'application/json' Any assistance with this would be gratefully received

asked Jan 20, 2020 by richarddewis (260 points)
3,589 questions
3,278 answers
8,303 comments
548,123 users