Skip to content

Commit

Permalink
Add: Multilenguaje compatible (spanish , english).
Browse files Browse the repository at this point in the history
Add: function from filter from state
Add:PowerScheduledTasks.tests.ps1 . (Test file with Psate)
Update:README
Tested in windows 2003 and windows 8
  • Loading branch information
robertolabarca authored and robertolabarca committed Mar 21, 2013
1 parent 41c0255 commit 0013b17
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 12 deletions.
48 changes: 38 additions & 10 deletions PowerScheduledTasks/PowerScheduledTasks.psm1
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
# Windows Scheduled Tasks Management PowerShell Module
# http://powershell.codeplex.com
Import-LocalizedData -BindingVariable LengTable

function Get-ScheduledTaskFilterby{
[CmdletBinding()]
param(
[string]
[ValidateSet("Running", "Not Running", "Disabled", "Listo", "Deshabilitado")]
$TaskStatus=$LengTable.statusnotrun
)
$resu= Get-ScheduledTask | where {$_.TaskStatus -eq $TaskStatus}
return $resu
}

Function Get-winver{
$vtemp=[Environment]::OSVersion.Version.ToString()
if ($vtemp -match "6.2.9200"){
"8"
}
else{
"2003"
}

}

Function Get-ScheduledTask
{
[CmdletBinding()]
param (
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipelineByPropertyName=$true,ValueFromPipeline=$true)]
[string] $TaskName,
[string] $HostName )

Expand All @@ -20,17 +44,18 @@ Function Get-ScheduledTask
$Item = $Item -replace("""|\s","")
$SplitItem = $Item -split(",")
$ScheduledTaskName = $SplitItem[0]
$ScheduledTaskStatus = $SplitItem[3]
Write-Host $ScheduledTaskName
$ScheduledTaskStatus = if ("", $null -contains $SplitItem[3]) {$LengTable.statusnotrun} else {$lengTable.statusrun}
$vtem=Get-winver
if ("2008","7","8" -match $vtem){
$ScheduledTaskStatus = if (($LengTable.statusnotrun -eq $ScheduledTaskStatus) -and ($SplitItem[2] -eq $LengTable.statusdisa)) {$LengTable.statusdisa} else {$LengTable.statusnotrun}
}
else{
$ScheduledTaskStatus = if (($LengTable.statusnotrun -eq $ScheduledTaskStatus) -and ($SplitItem[1] -eq $LengTable.statusdisa)) {$LengTable.statusdisa} else {$LengTable.statusnotrun}
}

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
Expand All @@ -40,6 +65,8 @@ Function Get-ScheduledTask
}
}
}


Function Start-ScheduledTask
{
[CmdletBinding()]
Expand Down Expand Up @@ -71,4 +98,5 @@ Function Stop-ScheduledTask
}
}

Export-ModuleMember -Function *
Export-ModuleMember -Function *

80 changes: 80 additions & 0 deletions PowerScheduledTasks/PowerScheduledTasks.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
TestScope "PowerScheduledTasks.psm1" {

# import the script
Import-Module ".\PowerScheduledTasks.psm1"
Enable-Mock | iex
Describing "PowerScheduledTasks" {

Given "PowerScheduledTasks" {
TestSetup {
Mock Get-ScheduledTask {
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Prueba"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Listo"
$objScheduledTaskName | Where-Object { $_.TaskName -match $TaskName }
} -When {$TaskStatus -eq "Listo"}

Mock Get-ScheduledTask {
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "PruebaDes"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Deshabilitado"

$objScheduledTaskName | Where-Object { $_.TaskName -match $TaskName }

} -When {$TaskStatus -eq "Deshabilitado"}

Mock Get-ScheduledTask{
$obj=new-object System.Collections.ArrayList
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea1"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Deshabilitado"
$obj.Add($objScheduledTaskName)
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea2"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Deshabilitado"
$obj.Add($objScheduledTaskName)
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea3"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Listo"
$obj.Add($objScheduledTaskName)
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea4"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Ejecut ndose"
$obj.Add($objScheduledTaskName)
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea5"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Listo"
$obj.Add($objScheduledTaskName)
$objScheduledTaskName = New-Object System.Object
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskName -Value "Tarea6"
$objScheduledTaskName | Add-Member -MemberType NoteProperty -Name TaskStatus -Value "Ejecut ndose"
$obj.Add($objScheduledTaskName)
$obj

}

}


It "Get-ScheduledTaskFilterby" {
$TaskStatus="Listo"
$resu= Get-ScheduledTaskFilterby -TaskStatus "Listo"
$resu.TaskName | should be "Prueba"
}

It "Get-ScheduledTaskFilterby" {
$TaskStatus="Deshabilitado"
$resu= Get-ScheduledTaskFilterby -TaskStatus "Deshabilitado"
$resu.TaskName | should be "PruebaDes"
}

It "Get-ScheduledTaskFilterby" {
$TaskStatus="Deshabilitado"
$resu= Get-ScheduledTaskFilterby -TaskStatus "Ejecut ndose"
$resu.count | should be 2
}
}
}
}


5 changes: 3 additions & 2 deletions PowerScheduledTasks/README
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ PowerShell Module that allows you to control Windows Scheduled Tasks

Requirements :

PowerShell 2.0
PowerShell
Schtasks.exe

For Windows Vista Systems and above, you can use these modules : http://code.msdn.microsoft.com/PowerShellPack


USAGE
Expand All @@ -27,6 +26,8 @@ You can pipe Commands like this :

List of Available Commands :

Get-ScheduledTaskFilterby
Get-winver (* internal)
Get-ScheduledTask
Start-ScheduledTask
Stop-ScheduledTask
5 changes: 5 additions & 0 deletions PowerScheduledTasks/en-US/PowerScheduledTasks.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ConvertFrom-StringData @'
statusdisa = Disabled
statusrun = Running
statusnotrun = Not Running
'@
5 changes: 5 additions & 0 deletions PowerScheduledTasks/es-ES/PowerScheduledTasks.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ConvertFrom-StringData @'
statusdisa = Deshabilitado
statusrun = Ejecut ndose
statusnotrun = Listo
'@

0 comments on commit 0013b17

Please sign in to comment.