How to Schedule a PowerShell Script

Dmitry's Blog: Cloud, PowerShell and beyond

Despite multiplearticles on that in the blogospherealready I keep getting questions on running PowerShell as Windows scheduled tasks – so here’s a quick summary what I see as the way to do this (assuming that you are running PowerShell 2.0). I hope you learn something new.

1. Get your script ready

Surprising as it might sound, your script might actually not be ready to run in a scheduled task as is. This happens if it uses cmdlets from a particular PowerShell module or snapin, and it worked for you interactively because you used a specialized shell (e.g. Exchange Management Shell) or a tool like PowerGUI Script Editor which loads the modules for you.

If you indeed are using using any non-default cmdlets, simply add Add-PSSnapin or Import-Module to the beginning of the script. For example:

Add-PSSnapinQuest.ActiveRoles.ADManagement

2. Schedule the task

To schedule a task simply start Windows…

Ver la entrada original 724 palabras más

One response to this post.

  1. Hello there, I discovered your site by the use of Google at the same time as looking for a related topic, your website got here up, it seems to be great. I have bookmarked it in my google bookmarks.

    Responder

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: