-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christophe CREMON
committed
Jul 6, 2012
1 parent
3985c79
commit 6d137ad
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 * |