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 (680 points)

1 Answer

0 votes
by (6k 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

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

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 (220 points)
0 votes
1 answer

Hi Is there any possibility to add groups to "Operations" Panel, especially custom commands, in the WebGUI on the user like we can ... Custom Commands Offboarding Offboarding Initiation Offboarding Initiation Fasttrack Notifications Update Mobile Contract

asked Jul 30, 2021 by m.car (60 points)
0 votes
1 answer

Hi there, i've a custom command with multiple powershell scripts (for clearance reasons). If for example the frist script produces an error i Write an Error but the next ... tried with an simple exit 1; I only Write-Errors on issues. Kind regards, Constantin

asked Jul 23, 2021 by Constey (170 points)
2,629 questions
2,364 answers
6,272 comments
962,129 users