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

Commit

Permalink
see changelog for v1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Oct 23, 2018
1 parent fc111b5 commit 918007e
Show file tree
Hide file tree
Showing 24 changed files with 420 additions and 342 deletions.
4 changes: 2 additions & 2 deletions MyTasks.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RootModule = 'MyTasks.psm1'

# Version number of this module.
ModuleVersion = '1.6.0'
ModuleVersion = '1.7.0'

# ID used to uniquely identify this module
GUID = '6a5db6e0-9669-4178-a176-54b4931aa4e2'
Expand All @@ -24,7 +24,7 @@ CompanyName = 'JDH Information Technology Solutions, Inc.'
Copyright = '(c) 2016-2018 JDH Information Technology Solutions, Inc. All rights reserved.'

# Description of the functionality provided by this module
Description = 'A tool set for managing tasks or to-do projects in PowerShell.'
Description = 'A tool set for managing tasks or to-do projects in PowerShell. Task data is stored in XML and managed through a PowerShell class.'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.0'
Expand Down
42 changes: 18 additions & 24 deletions MyTasks.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#requires -version 5.0

#region variables

Expand All @@ -20,33 +19,28 @@ $global:mytaskPath = Join-Path -Path $mytaskhome -ChildPath myTasks.xml
$global:myTaskArchivePath = Join-Path -Path $mytaskhome -ChildPath myTasksArchive.xml

#default task categories
$myTaskDefaultCategories = "Work","Personal","Other","Customer"
$myTaskDefaultCategories = "Work", "Personal", "Other", "Customer"

#endregion

#dot source functions
. $psscriptroot\MyTasksFunctions.ps1

#define some aliases
$aliases = @()
$aliases+= Set-Alias -Name gmt -Value Get-MyTask -PassThru
$aliases+= Set-Alias -Name smt -Value Set-MyTask -PassThru
$aliases+= Set-Alias -Name shmt -Value Show-MyTask -PassThru
$aliases+= Set-Alias -Name rmt -Value Remove-MyTask -PassThru
$aliases+= Set-Alias -Name cmt -Value Complete-MyTask -PassThru
$aliases+= Set-Alias -Name nmt -Value New-MyTask -PassThru
$aliases+= Set-Alias -name task -value New-MyTask -PassThru
$aliases+= Set-Alias -Name Archive-MyTask -Value Save-MyTask -PassThru

#define a hashtable of parameters to splat to Export-ModuleMember
$exportParams = @{
#Variable = "myTaskPath","myTaskDefaultCategories","myTaskArchivePath","mytaskhome"
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","Set-MyTaskPath"
Alias = $aliases.Name
$cmd = "Get-MyTask", "Set-MyTask", "Complete-MyTask", "Remove-MyTask"
Register-ArgumentCompleter -CommandName $cmd -ParameterName Name -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

[xml]$In = Get-Content -Path $MyTaskPath -Encoding UTF8

#$in.objects.object.childnodes.where( {$_.Name -eq 'Name'}).'#text'
foreach ($obj in $in.Objects.object) {
$obj.Property | ForEach-Object -Begin {$propHash = [ordered]@{}} -Process {
$propHash.Add($_.name, $_.'#text')
}
$propHash |
foreach-object {
# completion text,listitem text,result type,Tooltip
[System.Management.Automation.CompletionResult]::new($_.Name, $_.Name, 'ParameterValue', "Due: $($_.DueDate) Completed: $($_.completed)")
}
}
}

#exported via manifest
Export-ModuleMember @exportParams
117 changes: 80 additions & 37 deletions MyTasksFunctions.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#requires -version 5.0

#region class definition

Expand Down Expand Up @@ -119,6 +118,9 @@ Function _ImportTasks {
Function New-MyTask {

[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "Date")]
[OutputType("MyTask")]
[Alias("nmt", "task")]

Param(
[Parameter(
Position = 0,
Expand Down Expand Up @@ -214,8 +216,7 @@ Function New-MyTask {
@{Name = 'TaskCreated'; Expression = {Get-Date -Date $task.TaskCreated -Format 's'}},
@{Name = 'TaskModified'; Expression = {Get-Date -Date $task.TaskModified -Format 's'}},
TaskID,
Completed |
ConvertTo-Xml
Completed | ConvertTo-Xml

Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] $($newXML | out-string)"

Expand All @@ -241,7 +242,7 @@ Function New-MyTask {
if ($PSCmdlet.ShouldProcess($task.name)) {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Saving to existing file"
#need to save to a filesystem path
# $save = Convert-Path $mytaskPath
# $save = Convert-Path $mytaskPath
$in.Save($myTaskPath)
}
}
Expand All @@ -264,7 +265,7 @@ Function New-MyTask {
#save the file
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Saving the new file to $myTaskPath"
#need to save to a filesystem path
# $save = Convert-Path $mytaskPath
# $save = Convert-Path $mytaskPath
$newxml.Save($myTaskPath)
}
}
Expand All @@ -285,6 +286,9 @@ Function New-MyTask {
Function Set-MyTask {

[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "Name")]
[OutputType("None", "MyTask")]
[Alias("smt")]

Param (
[Parameter(
ParameterSetName = "Task",
Expand Down Expand Up @@ -351,7 +355,7 @@ Function Set-MyTask {
[string]$pb = ($PSBoundParameters | format-table -AutoSize | Out-String).TrimEnd()
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] PSBoundparameters: `n$($pb.split("`n").Foreach({"$("`t"*4)$_"}) | Out-String) `n"

Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Cleaning PSBoundparameters"
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Cleaning PSBoundParameters"
$PSBoundParameters.Remove("Verbose") | Out-Null
$PSBoundParameters.Remove("WhatIf") | Out-Null
$PSBoundParameters.Remove("Confirm") | Out-Null
Expand Down Expand Up @@ -445,6 +449,9 @@ Function Set-MyTask {

Function Remove-MyTask {
[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "Name")]
[OutputType("None")]
[Alias("rmt")]

Param(
[Parameter(
Position = 0,
Expand Down Expand Up @@ -517,7 +524,7 @@ Function Remove-MyTask {
#save file
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Updating $MyTaskPath"
#need to save to a filesystem path
# $save = Convert-Path $mytaskPath
# $save = Convert-Path $mytaskPath
$in.Save($mytaskpath)
} #should process
}
Expand All @@ -535,6 +542,8 @@ Function Remove-MyTask {

Function Get-MyTask {
[cmdletbinding(DefaultParameterSetName = "Days")]
[OutputType("MyTask")]
[Alias("gmt")]

Param(
[Parameter(
Expand All @@ -543,7 +552,7 @@ Function Get-MyTask {
)]
[string]$Name,
[Parameter(ParameterSetName = "ID")]
[int]$ID,
[int[]]$ID,
[Parameter(ParameterSetName = "All")]
[switch]$All,
[Parameter(ParameterSetName = "Completed")]
Expand Down Expand Up @@ -627,7 +636,8 @@ Function Get-MyTask {

"ID" {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Retrieving Task by ID: $ID"
$results = $tasks.where( {$_.id -eq $ID})
#$results = $tasks.where( {$_.id -eq $ID})
$results = $tasks.where({$_.id -match "^($($id -join '|'))$" })
} #id

"All" {
Expand Down Expand Up @@ -672,6 +682,9 @@ Function Show-MyTask {
#this may not work in the PowerShell ISE

[cmdletbinding(DefaultParameterSetName = "Days")]
[OutputType("None")]
[Alias("shmt")]

Param(
[Parameter(ParameterSetName = "all")]
[switch]$All,
Expand Down Expand Up @@ -799,6 +812,9 @@ Function Show-MyTask {
Function Complete-MyTask {

[cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "Name")]
[OutputType("None", "MyTask")]
[Alias("cmt")]

Param (
[Parameter(
ParameterSetName = "Task",
Expand Down Expand Up @@ -929,6 +945,8 @@ Function Complete-MyTask {

Function Get-MyTaskCategory {
[cmdletbinding()]
[OutputType([System.String])]

Param()

Begin {
Expand All @@ -954,6 +972,8 @@ Function Get-MyTaskCategory {
Function Add-MyTaskCategory {

[cmdletbinding(SupportsShouldProcess)]
[OutputType("None")]

Param(
[Parameter(
Position = 0,
Expand Down Expand Up @@ -997,6 +1017,8 @@ Function Add-MyTaskCategory {
Function Remove-MyTaskCategory {

[cmdletbinding(SupportsShouldProcess)]
[OutputType("None")]

Param(
[Parameter(
Position = 0,
Expand Down Expand Up @@ -1039,6 +1061,8 @@ Function Remove-MyTaskCategory {
Function Backup-MyTaskFile {

[cmdletbinding(SupportsShouldProcess)]
[OutputType("None", "System.IO.FileInfo")]

Param(
[Parameter(
Position = 0,
Expand Down Expand Up @@ -1095,6 +1119,9 @@ Function Backup-MyTaskFile {
Function Save-MyTask {

[cmdletbinding(SupportsShouldProcess)]
[OutputType("None", "myTask")]
[Alias("Archive-MyTask")]

Param(
[Parameter(Position = 0)]
[ValidateNotNullorEmpty()]
Expand Down Expand Up @@ -1183,7 +1210,10 @@ Function Save-MyTask {
}

Function Enable-EmailReminder {
#this function requires the PSScheduledJob module
[cmdletbinding(SupportsShouldProcess)]
[OutputType("None")]

Param(
[Parameter(Position = 0, HelpMessage = "What time do you want to send your daily email reminder?")]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -1236,7 +1266,7 @@ Function Enable-EmailReminder {
$hash | Out-String | Write-Verbose
#define the job scriptblock
$sb = {
Param([hashtable]$Hash,[int]$Dayy,[string]$myPath)
Param([hashtable]$Hash, [int]$Dayy, [string]$myPath)
#uncomment for troubleshooting
#$PSBoundParameters | out-string | write-host -ForegroundColor cyan
#get tasks for the next 3 days as the body
Expand All @@ -1248,23 +1278,23 @@ Function Enable-EmailReminder {
Write-Host "[$((Get-Date).ToString())] Sending as HTML" -ForegroundColor green
#css to be embedded in the html document
$head = @"
<Title>Upcoming Tasks</Title>
<style>
body { background-color:rgb(199, 194, 194);
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
tr:nth-child(odd) {background-color: lightgray}
table { width:95%;margin-left:5px; margin-bottom:20px;}
.alert {color: red ;}
.warn {color:#ff8c00;}
</style>
<br>
<H1>My Tasks</H1>
<Title>Upcoming Tasks</Title>
<style>
body { background-color:rgb(199, 194, 194);
font-family:Tahoma;
font-size:12pt; }
td, th { border:1px solid black;
border-collapse:collapse; }
th { color:white;
background-color:black; }
table, tr, td, th { padding: 2px; margin: 0px }
tr:nth-child(odd) {background-color: lightgray}
table { width:95%;margin-left:5px; margin-bottom:20px;}
.alert {color: red ;}
.warn {color:#ff8c00;}
</style>
<br>
<H1>My Tasks</H1>
"@
[xml]$html = $data | ConvertTo-HTML -Fragment

Expand Down Expand Up @@ -1338,7 +1368,7 @@ Function Enable-EmailReminder {
ScriptBlock = $sb
Name = "myTasksEmail"
Trigger = $Trigger
ArgumentList = $hash,$Days,$TaskPath
ArgumentList = $hash, $Days, $TaskPath
MaxResultCount = 5
ScheduledJobOption = $opt
Credential = $TaskCredential
Expand All @@ -1359,23 +1389,30 @@ Function Enable-EmailReminder {

Function Disable-EmailReminder {
[cmdletbinding(SupportsShouldProcess)]
[OutputType("None")]

Param()
Begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)"
} #begin

Process {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Processing"
Try {
if (Get-ScheduledJob -Name myTasksEmail -ErrorAction stop) {
#The cmdlet appears to ignore -WhatIf so I'll handle it myself
if ($PSCmdlet.ShouldProcess("myTasksEmail")) {
Unregister-ScheduledJob -Name myTasksEmail -ErrorAction stop
} #should process
} #if task found
if ((Get-Module PSScheduledJob) -And (($PSVersionTable.Platform -eq 'Win32NT') -OR ($PSVersionTable.PSEdition -eq 'Desktop'))) {
Try {
if (Get-ScheduledJob -Name myTasksEmail -ErrorAction stop) {
#The cmdlet appears to ignore -WhatIf so I'll handle it myself
if ($PSCmdlet.ShouldProcess("myTasksEmail")) {
Unregister-ScheduledJob -Name myTasksEmail -ErrorAction stop
} #should process
} #if task found
}
Catch {
Write-Warning "Can't find any matching scheduled jobs with the name 'myTasksEmail'."
}
}
Catch {
Write-Warning "Can't find any matching scheduled jobs with the name 'myTasksEmail'."
else {
Write-Warning "This command requires the PSScheduledJob module on a Windows platform."
}
} #process

Expand All @@ -1396,6 +1433,7 @@ Function Get-EmailReminder {

Process {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Getting scheduled job myTasksEmail"
if ((Get-Module PSScheduledJob) -And (($PSVersionTable.Platform -eq 'Win32NT') -OR ($PSVersionTable.PSEdition -eq 'Desktop'))) {
$t = Get-ScheduledJob myTasksEmail

$hash = $t.InvocationInfo.Parameters[0].where( {$_.name -eq "argumentlist"}).value
Expand Down Expand Up @@ -1430,6 +1468,10 @@ Function Get-EmailReminder {
Errors = $last.Errors
Warnings = $last.warnings
}
}
else {
Write-Warning "This command requires the PSScheduledJob module on a Windows platform."
}
} #process

End {
Expand All @@ -1441,6 +1483,7 @@ Function Get-EmailReminder {

Function Set-MyTaskPath {
[cmdletbinding(SupportsShouldProcess)]
[OutputType("None",[System.Management.Automation.PSVariable])]
Param(
[Parameter(Mandatory, HelpMessage = "Enter the path to your new myTaskPath directory")]
[ValidateScript( {Test-Path $_})]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ You should read full help and examples for all commands as well as the [about_My

Please post any issues, questions or feature requests in the [Issues](https://github.com/jdhitsolutions/MyTasks/issues) section.

*last updated 20 June 2018*
*last updated 22 October 2018*
Loading

0 comments on commit 918007e

Please sign in to comment.