Skip to content

Commit

Permalink
PowerScheduledTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe CREMON committed Jul 6, 2012
1 parent 3985c79 commit 6d137ad
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions PowerScheduledTasks/PowerScheduledTasks.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Windows Scheduled Tasks Management PowerShell Module
# http://powershell.codeplex.com

Function Get-ScheduledTask
{
[CmdletBinding()]
param (
[ValidateNotNullOrEmpty()]
[string] $TaskName,
[string] $HostName )

process
{
if ( $HostName ) { $HostName = "/S $HostName" }
$ScheduledTasks = SCHTASKS.EXE /QUERY /FO CSV /NH $HostName
foreach ( $Item in $ScheduledTasks )
{
if ( $Item -ne "" )
{
$Item = $Item -replace("""|\s","")
$SplitItem = $Item -split(",")
$ScheduledTaskName = $SplitItem[0]
$ScheduledTaskStatus = $SplitItem[3]
if ( $ScheduledTaskName -ne "" )
{
if ( $ScheduledTaskStatus -eq "" )
{
$ScheduledTaskStatus = "Not Running"
}
else
{
$ScheduledTaskStatus = "Running"
}
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value $ScheduledTaskName
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value $ScheduledTaskStatus
$objScheduledTaskName | Where-Object { $_.TaskName -match $TaskName }
}
}
}
}
}
Function Start-ScheduledTask
{
[CmdletBinding()]
param (
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
[string] $TaskName,
[string] $HostName )

process
{
if ( $HostName ) { $HostName = "/S $HostName" }
SCHTASKS.EXE /RUN /TN $TaskName $HostName
}
}
Function Stop-ScheduledTask
{
[CmdletBinding()]
param (
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)]
[string] $TaskName,
[string] $HostName )

process
{
if ( $HostName ) { $HostName = "/S $HostName" }
SCHTASKS.EXE /END /TN $TaskName $HostName
}
}

Export-ModuleMember -Function *

0 comments on commit 6d137ad

Please sign in to comment.