Schedule PowerShell scripts

Posted: January 25, 2012 in Exchange 2010, Powershell
Tags: , , , , , ,

You can start PowerShell scripts via taskplaner using a batch file
startscript.bat ->

Powershell.exe -command “.’C:\Scripts\script.ps1′”

script.ps1 ->

$localhost    = $env:COMPUTERNAME
#load exchange ps snapin if necessary
If ((Get-PSSnapin  | Where-Object {$_.Name -eq “Microsoft.Exchange.Management.PowerShell.E2010”} ).name -eq ‘Microsoft.Exchange.Management.PowerShell.E2010’)
{
Write-Host “Exchange Snapin loaded”
}

else
{
Write-Host “Loading Exchange Snapin”; Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
Write-Host “running”

After this you can insert your script code.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s