how can i schedule this exchage shell command

dougdog
dougdog used Ask the Experts™
on
Get-Mailbox -OrganizationalUnit "OU=3rd Party Contractors,DC=company,DC=co,DC=uk" | Set-Mailbox -CustomAttribute1 "ExcludeFromAllUsers"

I have tried several commands on internet but nothing works
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Have you tried saving it as a .ps1 file and running it from task scheduler within Windows?....

Author

Commented:
yes but cant seem to get the commands right
What errors are you seeing?...
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Thomas GrassiSystems Administrator

Commented:
You need to load the exchange powershell set first

create yourself a batch file that will call your powershell script and will load the exchange shell also

This is how I do it

@echo off
cd\util
PowerShell.exe -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\V14\Bin\ExShell.psc1" -Command "./EASDevicestats.ps1"
exit


This works then you can add the batch file to your task schedular

Of course you can name your powershell what ever you want

HTH

Author

Commented:
do you create a util folder on the c drive and copy ps1 script file into it?
Thomas GrassiSystems Administrator

Commented:
yes you can or what ever folder you wish to use

put the ps1 and cmd file in the same folder

Author

Commented:
Thomas Thats bang on perfect i have been messing about for ages trying to get this to work
Excellent thank you so much

would it be hard to get this task to email success /failure??
Systems Administrator
Commented:
It will be successful for sure

Author

Commented:
perfect thanks again appreciate it
Thomas GrassiSystems Administrator

Commented:
Glad I was able to help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial