Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
Added a patch to store date in an ISO friendly format. (Issue #23 and Issue #22)
Added a new function, Set-MyTaskPath to allow you to update the task folder (Issue #20)
Updated documentation
  • Loading branch information
jdhitsolutions committed May 22, 2018
1 parent 072d493 commit f3452c4
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 138 deletions.
Binary file modified MyTasks.psd1
Binary file not shown.
4 changes: 3 additions & 1 deletion MyTasks.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ if ($isLinux) {
else {
$mytaskhome = "$home\Documents"
}

#path to the category file
$myTaskCategory = Join-Path -Path $mytaskhome -ChildPath myTaskCategory.txt

#path to stored tasks
Expand Down Expand Up @@ -42,7 +44,7 @@ Variable = "myTaskPath","myTaskDefaultCategories","myTaskArchivePath","mytaskhom
Function = "New-MyTask","Set-MyTask","Remove-MyTask","Get-MyTask",
"Show-MyTask","Complete-MyTask","Get-MyTaskCategory","Add-MyTaskCategory",
"Remove-MyTaskCategory","Backup-MyTaskFile","Save-MyTask","Enable-EmailReminder",
"Disable-EmailReminder","Get-EmailReminder"
"Disable-EmailReminder","Get-EmailReminder","Set-MyTaskPath"
Alias = $aliases.Name
}

Expand Down
81 changes: 51 additions & 30 deletions MyTasksFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ Function New-MyTask {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Converting to XML"
$newXML = $task |
Select-object -property Name,
Description,
@{Name = 'DueDate'; Expression = {Get-Date -Date $task.DueDate -Format 's'}},
Category,
Progress,
@{Name = 'TaskCreated'; Expression = {Get-Date -Date $task.TaskCreated -Format 's'}},
@{Name = 'TaskModified'; Expression = {Get-Date -Date $task.TaskModified -Format 's'}},
TaskID,
Completed |
Description,
@{Name = 'DueDate'; Expression = {Get-Date -Date $task.DueDate -Format 's'}},
Category,
Progress,
@{Name = 'TaskCreated'; Expression = {Get-Date -Date $task.TaskCreated -Format 's'}},
@{Name = 'TaskModified'; Expression = {Get-Date -Date $task.TaskModified -Format 's'}},
TaskID,
Completed |
ConvertTo-Xml

Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] $($newXML | out-string)"
Expand Down Expand Up @@ -867,14 +867,14 @@ Function Complete-MyTask {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Updating task file"
#convert current task to XML
$new = ($task | Select-object -property Name,
Description,
@{Name = 'DueDate'; Expression = {Get-Date -Date $task.DueDate -Format 's'}},
Category,
Progress,
@{Name = 'TaskCreated'; Expression = {Get-Date -Date $task.TaskCreated -Format 's'}},
@{Name = 'TaskModified'; Expression = {Get-Date -Date $task.TaskModified -Format 's'}},
TaskID,
Completed | ConvertTo-Xml).Objects.Object
Description,
@{Name = 'DueDate'; Expression = {Get-Date -Date $task.DueDate -Format 's'}},
Category,
Progress,
@{Name = 'TaskCreated'; Expression = {Get-Date -Date $task.TaskCreated -Format 's'}},
@{Name = 'TaskModified'; Expression = {Get-Date -Date $task.TaskModified -Format 's'}},
TaskID,
Completed | ConvertTo-Xml).Objects.Object

#load tasks from XML
[xml]$In = Get-Content -Path $MyTaskPath -Encoding UTF8
Expand Down Expand Up @@ -1383,32 +1383,32 @@ Function Get-EmailReminder {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting scheduled job myTasksEmail"
$t = Get-ScheduledJob myTasksEmail

$hash = $t.InvocationInfo.Parameters[0].where({$_.name -eq "argumentlist"}).value
$hash = $t.InvocationInfo.Parameters[0].where( {$_.name -eq "argumentlist"}).value

Try {
#get the last run
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting last job run"
$last = Get-Job $t.name -Newest 1 -ErrorAction stop
}
}
Catch {
$last = [PSCustomObject]@{
PSEndTime = "11/30/1999" -as [datetime]
State = "The task has not yet run"
State = "The task has not yet run"
}
}
[pscustomobject]@{
Task = $t.Name
Frequency = $t.JobTriggers.Frequency
At = $t.JobTriggers.at.TimeOfDay
To = $hash.To
From = $hash.From
Task = $t.Name
Frequency = $t.JobTriggers.Frequency
At = $t.JobTriggers.at.TimeOfDay
To = $hash.To
From = $hash.From
MailServer = $hash.SMTPServer
Port = $hash.Port
UseSSL = $hash.UseSSL
AsHTML = $hash.BodyAsHTML
LastRun = $last.PSEndTime
LastState = $last.State
Enabled = $t.Enabled
Port = $hash.Port
UseSSL = $hash.UseSSL
AsHTML = $hash.BodyAsHTML
LastRun = $last.PSEndTime
LastState = $last.State
Enabled = $t.Enabled
}
} #process

Expand All @@ -1419,6 +1419,27 @@ Function Get-EmailReminder {

} #close Get-EmailReminder

Function Set-MyTaskPath {
[cmdletbinding(SupportsShouldProcess)]
Param(
[Parameter(Mandatory, HelpMessage = "Enter the path to your new myTaskPath directory")]
[ValidateScript( {Test-Path $_})]
[string]$Path
)

If ($pscmdlet.ShouldProcess("$path", "Update task path")) {
$global:mytaskhome = $Path

#path to the category file
$global:myTaskCategory = Join-Path -Path $mytaskhome -ChildPath myTaskCategory.txt

#path to stored tasks
$global:mytaskPath = Join-Path -Path $mytaskhome -ChildPath myTasks.xml

#path to archived or completed tasks
$global:myTaskArchivePath = Join-Path -Path $mytaskhome -ChildPath myTasksArchive.xml

}
} #close Set-MyTaskPath


46 changes: 34 additions & 12 deletions Tests/MyTasks.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ InModuleScope MyTasks {
Describe "The module" {

$theModule = get-module -name mytasks
It "Should have 14 functions" {
$theModule.exportedfunctions.count | should be 14
It "Should have 15 functions" {
$theModule.exportedfunctions.count | should be 15
}

It "Should have 8 aliases command" {
Expand Down Expand Up @@ -67,20 +67,22 @@ Describe Tasks {

<#
It doesn't appear that you can consistently mock commands that might be used in a class
so we'll use actual the actual date
so we'll use the actual date
#>

$Due = (Get-Date).AddDays(30).Date

#need absolute path for XML files
new-Item -Name Documents -ItemType Directory -path $TestDrive
new-Item -Name Documents -ItemType Directory -path TestDrive:
$home = $TestDrive
$mytaskhome = "$home\Documents"
$mytaskhome = Join-Path $home -childpath Documents
$mytaskPath = Join-Path $home\Documents -child "myTasks.xml"
$myTaskArchivePath = Join-Path -Path $home\Documents -ChildPath "myTasksArchive.xml"
$myTaskCategory = Join-Path -path $home\Documents -childpath "myTaskCategory.txt"

Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing

#gv mytask* | out-string | write-host -ForegroundColor yellow

It "Should create a new task" {
$a = New-MyTask -Name Test1 -DueDate $Due -Category Testing -Passthru
$a.id | Should be 1
Expand Down Expand Up @@ -148,16 +150,18 @@ Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing
(Get-MyTask -Completed | Measure-Object).Count | Should be 1
}

Context Archive {

$save = Join-path $TestDrive -ChildPath "Archive.xml"
It "Should complete and archive a task" {
{Complete-Mytask -Name Test2 -Archive -ErrorAction Stop} | Should Not Throw
(Get-MyTask -all | where-object {-not $_.completed}).count | Should be 3
}

It "Should archive or save a task" {
$save = Join-path $TestDrive -ChildPath "Archive.xml"
Get-MyTask -Completed | Save-MyTask -Path $save
Test-Path $save | should Be $True
Get-MyTask -Name Test1 | Should Be $null
Get-MyTask -Name Test1 -WarningAction SilentlyContinue | Should Be $null
(Get-MyTask -all).count | Should be 3
}

Expand All @@ -166,7 +170,8 @@ Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing
$c.Displayname | should be "Archive-MyTask"
$c.ReferencedCommand | Should be "Save-MyTask"
}

}
Context Backup {
It "Should remove a task and backup the task file" {
{Remove-myTask -Name Alice } | Should not Throw
{Get-MyTask -Name Bob | Remove-MyTask } | should not Throw
Expand All @@ -175,11 +180,28 @@ Add-MyTaskCategory -Category Work,Personal,Other,Training,Testing

It "Should backup the task file" {
{Backup-MyTaskFile -ErrorAction Stop} | Should Not Throw
#dir $TestDrive -Recurse | out-string | write-host
Test-Path $TestDrive\documents\MyTasks_Backup_*.xml | Should be $True
#dir TestDrive: -Recurse | out-string | write-host
Test-Path TestDrive:\documents\MyTasks_Backup_*.xml | Should be $True
}
}

} #describe my tasks

Describe TaskVariables {

It "Set-MyTaskPath should change the global module variables" {
$new = Join-Path -Path $TestDrive -ChildPath MyTasks
new-item $new -ItemType Directory
{Set-MyTaskPath -path $new }
}
$vars = 'myTaskArchivePath','myTaskCategory','mytaskhome','mytaskPath'
foreach ($var in $vars) {
It "Should update $var" {
(get-variable var).value | Should match $new
}
}
<# myTaskArchivePath C:\Users\jeff\Documents\myTasksArchive.xml
myTaskCategory C:\users\jeff\Dropbox\mytasks\myTaskCategory.txt
mytaskhome C:\Users\jeff\Documents
mytaskPath C:\Users\jeff\Documents\myTasks.xml
#>} #describe TaskVariables
} #in module
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changelog for MyTasks

v1.5.0
Added a patch to store date in an ISO friendly format. (Issue #23 and Issue #22)
Added a new function, Set-MyTaskPath to allow you to update the task folder (Issue #20)
Updated documentation

v1.4.0
Added support for PowerShell scheduled job to email upcoming tasks (Issue #17)
Scheduled reminders will be a Windows only feature.
Expand Down
101 changes: 101 additions & 0 deletions docs/Set-MyTaskPath.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
external help file: MyTasks-help.xml
Module Name: MyTasks
online version:
schema: 2.0.0
---

# Set-MyTaskPath

## SYNOPSIS

Update the myTask variables

## SYNTAX

```
Set-MyTaskPath [-Path] <String> [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION

The MyTasks module relies on global variables to know where your task-related files are stored. The default on Windows systems is your Documents folder. In Linux it is your home folder. Use this command to modify the path. It will then update all of the related variables.

It is recommended that you modify your PowerShell profile to import this module and then run this command to reflect the correct location.

## EXAMPLES

### Example 1

```powershell
PS C:\> Set-MyTaskpath -path c:\users\pat\dropbox\tasks
```

This will put all of the task files in the Dropbox folder and update the corresponding variables.

## PARAMETERS

### -Confirm

Prompts you for confirmation before running the cmdlet.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Path

Enter the path to your new myTaskPath directory.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -WhatIf

Shows what would happen if the cmdlet runs.The cmdlet is not run.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### None

## NOTES

## RELATED LINKS
Loading

0 comments on commit f3452c4

Please sign in to comment.