Is it possible to call a powershell script from a sharepoint timer job ? or are there any security issues involved in doing so?
Regards, Jeevan
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityThere are a couple of ways of calling PowerShell from within code (e.g. within a timer job):
Run PowerShell Script using automation interface.
Run PowerShell using command line.
You have to give some thought to where the timer job is running, if you have a farm with multiple servers. The timer job normally runs as the farm account. You will also need to load up the SharePoint snap-in.
I can't see much technical advantage in doing this as everything you can do in PowerShell can be achieved using the object model. However, you may already have script written, or you might want to use a PowerShell cmdlet that would need to be re-implemented programmatically. I don't think it is completely unreasonable to do this, depending on what you are trying to achieve.
You can do it from a scheduled task, we do that for certain administrative tasks. Do you really need this to happen as a Timer Job from SharePoint or wouldn't a Scheduled Task do just as well? I don't see the need for a Timer Job since you can set the same sort of schedule as a Scheduled Task.
A timer job would usually be written in a .NET language and would therefore not have access to Powershell as such. There are some bodges you could use to do this, but it doesn't sound like a good idea.
What about scheduling a timer job to run this one?
Update-SPProfilePhotoStore –CreateThumbnailsForImportedPhotos 1 –MySiteHostLocation http://mysitehost/my
Seems like that should already run on some sort of a schedule.... doesn't appear to though...