0 votes

I have a custom command that uses powershell to set the room capacity for a resource mailbox in 0365. The command runs without any errors when called manually by right-clicking on the mailbox object and running. However, when the custom command is called from a scheduled task, it logs the following error even though it successfully sets the capacity. Any thoughts on why it logs an error when called from a scheduled task? Error: Encountered an internal server error. Stack trace: at <ScriptBlock><Process>, <No file>: line 84

The PowerShell:

Import-Module ExchangeOnlineManagement

$rmCapacity = %param-Capacity%
# Get the username in Office 365
try
{
    $UserAlias = [string]$Context.TargetObject.Get("Samaccountname")
}
catch
{
    $Context.LogMessage("The user doesn't have an Office 365 account", "Warning")
    return
}

try
{
    # Connect to Exchange Online
    Connect-ExchangeOnline -Credential $Context.GetOffice365Credential()

    # Change mailbox capacity
    Set-Place -Identity $UserAlias -Capacity $rmCapacity

}
catch
{
    $Context.LogMessage($_.Exception.Message, "Warning")
}
finally
{
    # Close the remote session and release resources
    Disconnect-ExchangeOnline -Confirm:$false
}
by (50 points)

1 Answer

0 votes
by (287k points)
selected by
Best answer

Hello,

Firstly, all value references in Adaxes scripts must be wrapped into double quotes. As such, the corresponding line in your script must be as follows:

$rmCapacity = "%param-Capacity%"

As for the error itself, it looks like it occurs inside of the Set-Place cmdlet (pay attention to the number of the line in the error). As per our check, there are known issues with the cmdlet that can result in such an error. The following thread on Microsoft forums might be helpful: https://answers.microsoft.com/en-us/msoffice/forum/all/set-place-command-and-room-finder/529ec10f-52b8-45cc-aaa5-8029c1f5422f.

As per our check, you can also use the -ResourceCapacity parameter of the Set-Mailbox cmdlet. It looks to be more reliable. In this case, your script will be as follows:

Import-Module ExchangeOnlineManagement

$rmCapacity = "%param-Capacity%"

# Get the username in Office 365
try
{
    $objectId = [Guid]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
    $Context.LogMessage("The user doesn't have an Office 365 account", "Warning")
    return
}

try
{
    # Connect to Exchange Online
    Connect-ExchangeOnline -Credential $Context.GetOffice365Credential()

    # Change mailbox capacity
    Set-Mailbox $objectId.ToString() -ResourceCapacity $rmCapacity
}
catch
{
    $Context.LogMessage($_.Exception.Message, "Warning")
}
finally
{
    # Close the remote session and release resources
    Disconnect-ExchangeOnline -Confirm:$false
}

If you still need to use the Set-Place cmdlet and the forum thread does not help, please, specify the difference when running the custom command manually and from a scheduled task. Is it done for the very same account? Is the account in the scope of a Microsoft 365 tenant in Adaxes? Any additional details will be very helpful.

0

Thanks for such a great reply!! I found that adding the quotes around the parameter did not resolve the internal server error. However, changing the cmdlet to Set-Mailbox did resolve the error.

Thanks again!

Related questions

0 votes
0 answers

Trying to configure a custom launcher in Thycotic Secret Server that will launch Adaxes on the user's local machine with the username and password passed as parameters. Has anyone made this work?

asked May 20, 2022 by amillard (20 points)
0 votes
1 answer

I'm moving from 2013.1 (on Server 2008 R2) to 2014.1 (on Server 2012 R2) and am going from a single server to 2 new servers and will shut down the 2013 ... be updated properly if their target object is moved or renamed. Would another reboot fix this possibly?

asked Aug 26, 2014 by danftasc (440 points)
0 votes
1 answer

Hi, I'm trying to open Adaxes object with Powershell script, and receive "object does not exist" error message. The script is executed remotely (not ... + FullyQualifiedErrorId : DotNetMethodException Any helps will be greatly appreciated. Thank you, Van

asked Apr 24, 2013 by vnguyen (20 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 (190 points)
0 votes
1 answer

I have a scheduled task that runs a custom command that itself has multiple custom commands that run in a specific timed order. I would like the scheduler to run that top level ... , but Command B and C will wait for Command A to finish. Is this possible?

asked Jul 23 by DA-symplr (100 points)
3,526 questions
3,217 answers
8,197 comments
547,625 users