CHiLL Posted October 13, 2015 Posted October 13, 2015 (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 October 13, 2015 by CHiLL
Steve21 Posted October 13, 2015 Posted October 13, 2015 $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
Chris_Jones Posted October 14, 2015 Posted October 14, 2015 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.
alexInnes Posted October 26, 2015 Posted October 26, 2015 You could use the task scheduling cmdlets to automate this on the server: https://technet.microsoft.com/en-us/library/jj649816(v=wps.630).aspx
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now