Avatar of dougdog
dougdog

asked on 

how can i schedule this exchage shell command

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
Exchange

Avatar of undefined
Last Comment
Member_2_6492660_1
Avatar of DLeaver
DLeaver
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you tried saving it as a .ps1 file and running it from task scheduler within Windows?....
Avatar of dougdog
dougdog

ASKER

yes but cant seem to get the commands right
Avatar of DLeaver
DLeaver
Flag of United Kingdom of Great Britain and Northern Ireland image

What errors are you seeing?...
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
Avatar of dougdog
dougdog

ASKER

do you create a util folder on the c drive and copy ps1 script file into it?
yes you can or what ever folder you wish to use

put the ps1 and cmd file in the same folder
Avatar of dougdog
dougdog

ASKER

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??
ASKER CERTIFIED SOLUTION
Avatar of Member_2_6492660_1
Member_2_6492660_1
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dougdog
dougdog

ASKER

perfect thanks again appreciate it
Glad I was able to help
Exchange
Exchange

Exchange is the server side of a collaborative application product that is part of the Microsoft Server infrastructure. Exchange's major features include email, calendaring, contacts and tasks, support for mobile and web-based access to information, and support for data storage.

213K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo