From 0013b1743c68456a6b2c43adf9bd1c246a6455fa Mon Sep 17 00:00:00 2001 From: robertolabarca Date: Thu, 21 Mar 2013 16:19:04 -0400 Subject: [PATCH] Add: Multilenguaje compatible (spanish , english). Add: function from filter from state Add:PowerScheduledTasks.tests.ps1 . (Test file with Psate) Update:README Tested in windows 2003 and windows 8 --- PowerScheduledTasks/PowerScheduledTasks.psm1 | 48 ++++++++--- .../PowerScheduledTasks.tests.ps1 | 80 +++++++++++++++++++ PowerScheduledTasks/README | 5 +- .../en-US/PowerScheduledTasks.psd1 | 5 ++ .../es-ES/PowerScheduledTasks.psd1 | 5 ++ 5 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 PowerScheduledTasks/PowerScheduledTasks.tests.ps1 create mode 100644 PowerScheduledTasks/en-US/PowerScheduledTasks.psd1 create mode 100644 PowerScheduledTasks/es-ES/PowerScheduledTasks.psd1 diff --git a/PowerScheduledTasks/PowerScheduledTasks.psm1 b/PowerScheduledTasks/PowerScheduledTasks.psm1 index 60d52bb..4ccca52 100644 --- a/PowerScheduledTasks/PowerScheduledTasks.psm1 +++ b/PowerScheduledTasks/PowerScheduledTasks.psm1 @@ -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 ) @@ -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 @@ -40,6 +65,8 @@ Function Get-ScheduledTask } } } + + Function Start-ScheduledTask { [CmdletBinding()] @@ -71,4 +98,5 @@ Function Stop-ScheduledTask } } -Export-ModuleMember -Function * \ No newline at end of file +Export-ModuleMember -Function * + diff --git a/PowerScheduledTasks/PowerScheduledTasks.tests.ps1 b/PowerScheduledTasks/PowerScheduledTasks.tests.ps1 new file mode 100644 index 0000000..48df1f2 --- /dev/null +++ b/PowerScheduledTasks/PowerScheduledTasks.tests.ps1 @@ -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 + } + } + } +} + + diff --git a/PowerScheduledTasks/README b/PowerScheduledTasks/README index d328698..7450c4b 100644 --- a/PowerScheduledTasks/README +++ b/PowerScheduledTasks/README @@ -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 @@ -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 \ No newline at end of file diff --git a/PowerScheduledTasks/en-US/PowerScheduledTasks.psd1 b/PowerScheduledTasks/en-US/PowerScheduledTasks.psd1 new file mode 100644 index 0000000..dddf605 --- /dev/null +++ b/PowerScheduledTasks/en-US/PowerScheduledTasks.psd1 @@ -0,0 +1,5 @@ +ConvertFrom-StringData @' + statusdisa = Disabled + statusrun = Running + statusnotrun = Not Running +'@ diff --git a/PowerScheduledTasks/es-ES/PowerScheduledTasks.psd1 b/PowerScheduledTasks/es-ES/PowerScheduledTasks.psd1 new file mode 100644 index 0000000..1befe61 --- /dev/null +++ b/PowerScheduledTasks/es-ES/PowerScheduledTasks.psd1 @@ -0,0 +1,5 @@ +ConvertFrom-StringData @' + statusdisa = Deshabilitado + statusrun = Ejecut�ndose + statusnotrun = Listo +'@ \ No newline at end of file