Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Last active September 18, 2024 20:28
Show Gist options
  • Save jdhitsolutions/d49aa6c1bf3eba9d4bfaf3eaa216e29a to your computer and use it in GitHub Desktop.
Save jdhitsolutions/d49aa6c1bf3eba9d4bfaf3eaa216e29a to your computer and use it in GitHub Desktop.
A PowerShell function that you can use to insert ToDo messages into your scripts and functions.
<#
based on a comment from Matt Penny
function todo {
param ([string]$TodoText)
write-host -foregroundcolor DarkYellow ” [o] Todo: $TodoText”
}
Get more from Matt at https://mattypenny.net/
#>
Function Write-ToDo {
[cmdletbinding()]
Param(
[Parameter(
Position=0,
Mandatory,
HelpMessage = "Enter a ToDo item")]
[string]$ToDo,
[Parameter(
Position = 1
)]
[ValidateNotNullorEmpty()]
#the default ToDo color
[consolecolor]$ForegroundColor = "Cyan"
)
Begin {
If (-Not $ToDoHistory) {
$global:ToDoHistory = @()
}
} #begin
Process {
#check ToDoHistory to make sure we haven't already displayed the item
#useful if the new function accepts pipeline input or when looping
if (-Not ($global:ToDoHistory -contains $ToDo)) {
$global:ToDoCounter++
#format the counter with 2 leading zeros
$msg = "[$($global:ToDoCounter.ToString("00#"))] TO-DO: $ToDo"
Write-Host $msg -ForegroundColor $ForegroundColor
$global:TodoHistory+=$ToDo
}
} #process
End {
#not used
} #end
} #Write-ToDo
Set-Alias -Name ToDo -Value Write-ToDo
Function Remove-ToDoVariable {
[cmdletbinding(SupportsShouldProcess)]
Param()
"ToDoCounter","ToDoHistory" | foreach {
#remove these variables from the global scope and ignore any errors
#for variables that don't exist
Remove-Variable -Name $_ -Scope global -ErrorAction SilentlyContinue
}
} #Remove-ToDoVariable
@jdhitsolutions
Copy link
Author

@jdhitsolutions
Copy link
Author

This functionality is now part of the PSScriptTools module https://github.com/jdhitsolutions/PSScriptTools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment