D
D
Dmytro Yunh2020-11-23 14:11:21
PowerShell
Dmytro Yunh, 2020-11-23 14:11:21

Exchange Powershell script, why are contacts not added when run from task scheduler?

Good afternoon, Khabrovites.

Initial data:
Platform: MS Exchange 2010
The MS Exchange server has a script that should create mail contacts and add them to a distribution group.
The mechanism of the script operation is approximately the following:
A file with a list of e-mail addresses is uploaded to a folder on the MS Exchange server
The script selects the uploaded file The following are
2 main actions of this script:
Loops through the lines of the file and creates new contacts using the New-MailContact cmdlet
Adding contacts to distribution group with the Add-DistributionGroupMember
cmdlet

To execute the script, a technology account is used, with sufficient rights, such as:
Allow logon as a batch job on the MS Exchange server Exchange
roles:
Organization Management
Recipient Management


contacts).

When the script is executed in the Exchange Powershell console launched on behalf of this technological user, all required actions are performed normally, i.e. contacts are created and added to the distribution group.

Please tell me where to dig in order to solve the problem of executing the script from the Windows Task Scheduler.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Eugene, 2020-11-23
@hugeous

Start-Transcript at the very beginning and Stop-Transcript at the very end will allow you to understand what happens during the execution of the script. And the history of the scheduled task launch will allow you to see if the script was launched at all. It may be that it simply does not start and the task scheduler itself crashes.

A
akelsey, 2020-11-23
@akelsey

More like magic, of course. If it works from the console on behalf of a specially created user, please make sure whoami is this user.
The second option is to change the contents of the script, or add a debug line at the beginning of the script and do exit to stop the script execution and make sure that the script is actually run under the user and outputs information to the file.
There is nothing more to advise, there is clearly no connection with Exchange -)

M
MaxKozlov, 2020-11-23
@MaxKozlov

modules for 2010 can be loaded by themselves, but Snapin's - no. Most likely this is the reason. it would be necessary to check on bare PS, instead of Exchange Powershell
Therefore for a start it is possible to launch the elementary script from the scheduler
Get-ExCommand >c:\temp\log
To be convinced that commands are available.
I don’t remember how it was in 2010, if Get-ExCommand is not available, then make Add-PSSnapin necessary and then Get-Command
If everything you need is available, add logs after each suspicious line

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question