Jump to content

Powershell, Office 365 commands and Task Scheduler


Recommended Posts

Posted (edited)

Hello,

I have a couple of tasks that I need to perform on a regular basis and would like to automate them. The main one at the moment is to enable and disable transport rules. I have the powershell command to perform this, however I don't know how to automate it. I'd like this automated task to live on our DirSync server, and be able to do this whether a user is logged into the server or not, and without the prompt for credentials.

 

At the moment, I have to manually enter my credentials and run the command using these commands:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Enable-TransportRule "Name of Transport Rule"

Is there any way to make this automated and then able to run as a scheduled task without being logged in?

 

Thanks

Edited by CHiLL
Posted

$User = "MyDomain\MyUser"
$PWord = ConvertTo-SecureString –String "MyEpicPassword" –AsPlainText -Force
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord

 

Obviously note that the password is plaintext in the script though

 

Steve

Posted

For the second part, assuming that the script is signed:

 

Setup the task with a suitable descriptive name and setup the triggers as needed.

 

it may be neccessary to set the tesk to 'Run with highest privileges'

 

On the Actions tab set the following

 

Actions:

Run: Powershell

Arguments: .\Scriptname.ps1

Start in: C:\Support

 

where C:\Support is the local folder where the script resides.

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...