PSNotes is a PowerShell module that allows you to create your own custom snippet library, that you can use to reference commands you run often. Or ones you don't run often and need a reminder on. Snippets can either be executed directly, copied to your clipboard, or simply output to the display for you to do whatever you want with them. When you create a note, you assign an alias to it, so you can have an easy to remember keyword that you can then use to recall it. Notes can also be classified with tags, so you can easily search for them.
When you create a new note, you can define an alias that you can later use to display or run it.
Perfect for long commands you need to run often.
You can assign tags to your notes to make searching easier.
Add new snippets as string or by using a script block
The import and export functionality allows you to share notes between machines and people.
PowerShell v5+ and PowerShell Core v6+
Install-Module PSNotes
Note: At of the time of publishing Set-Clipboard is not supported in PowerShell Core. To use the copy to clipboard functionality of this module, it is recommended that you also install the ClipboardText module.
Install-Module -Name ClipboardText
When you create a note in the PSNotes module you assign an alias to it. You can use this alias at any time to output, copy, or run a note. Simply type the name of the alias and hit enter to output it to your PowerShell console. You can also add the -copy
switch to have the note copied to your clipboard or use the -run
to execute the note directly.
This example gets the note/code snippet with the alias "MyNote" and outputs it to the console.
MyNote
This example gets the note/code snippet with the alias "MyNote" and outputs it to the console and copies it to your local clipboard.
MyNote -copy
This example gets the note/code snippet with the alias "MyNote" and executes the command in your local session.
MyNote -run
Don't worry if you can't remember the alias you assigned to a note. You can use Get-PSNote
to search your notes by name, tags, and keywords.
This example gets all the notes currently loaded in your profile.
Get-PSNote
This example gets all the notes that start with cred.
Get-PSNote -Name 'cred*'
This example gets all the notes that have a name with the word "user" in it.
Get-PSNote -Name '*user*'
This example gets all the notes that have the tag "AD" assigned to them.
Get-PSNote -Tag 'AD'
This example gets all the notes with the word "day" in the name, details, snippet text, alias, or tags.
Get-PSNote -SearchString 'day'
You can create your own notes at any time using New-PSNote
. Keep in mind that the snippet must be passed as string, so it is recommended to wrap them in single quotes and here-strings to prevent them from being executed when you are creating a note.
This example creates a new note for the Get-ADUser cmdlet. Since the -Alias
parameter is not supplied the Note value will be assigned as the alias.
New-PSNote -Note 'ADUser' -Snippet 'Get-ADUser -Filter *' -Details "Use to return all AD users" -Tags 'AD','Users'
This example creates a new note with a custom alias.
$Snippet = '(Get-Culture).DateTimeFormat.GetAbbreviatedDayName((Get-Date).DayOfWeek.value__)'
New-PSNote -Note 'DayOfWeek' -Snippet $Snippet -Details "Use to name of the day of the week" -Tags 'date' -Alias 'today'
This example creates a new note for the Get-WmiObject using a script block instead of a string. This make multiple line scripts easier to enter and gives you the ability to use auto-complete when entering it.
New-PSNote -Note 'CpuUsage' -Tags 'perf' -Alias 'cpu' -ScriptBlock {
Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average
}
This example shows one way you can create a new note for a snippet that contains both single and double quotes. Notice in the snippet itself the single quotes are doubled. This escapes them and tells PowerShell it is not the end of the string.
New-PSNote -Note 'SvcAccounts' -Snippet 'Get-ADUser -Filter ''Name -like "*SvcAccount"''' -Details "Use to return all AD Service Accounts" -Tags 'AD','Users'
When creating a note for a multiple line snippet, it is recommended that you use a here-string with single quotes to prevent expressions from being evaluated when you run the New-PSNote
command.
$Snippet = @'
$stringBuilder = New-Object System.Text.StringBuilder
for ($i = 0; $i -lt 10; $i++){
$stringBuilder.Append("Line $i`r`n") | Out-Null
}
$stringBuilder.ToString()
'@
New-PSNote -Note 'StringBuilder' -Snippet $Snippet -Details "Use StringBuilder to combine multiple strings" -Tags 'string'
You can update a note at any time using Set-PSNote
. With Set-PSNote
you can update the Snippet, Details, Tags, or Alias of any note. In addition, notes can be deleted using Remove-PSNote
.
This example shows how to add the tags "AD" and "User" to the note ADUser
Set-PSNote -Note 'ADUser' -Tags 'AD','Users'
This example shows how to update the snippet for the note DayOfWeek
$Snippet = '(Get-Culture).DateTimeFormat.GetAbbreviatedDayName((Get-Date).DayOfWeek.value__)'
Set-PSNote -Note 'DayOfWeek' -Snippet $Snippet
This example shows how to delete a note named creds. This command does not accept wildcards, so the name of the note must match exactly.
Remove-PSNote -Note 'creds'
Not only does PSNotes allow you to create your own custom notes. It allows you to share them between computers and users. You can create a list of notes export them and share them with your team. Notes are stored in easy to read and edit JSON files in case you want to make manual edits.
Note: PSNotes stores your notes in your local AppData folder using the path %appdata%\PSNotes. By default, it places them in the file PSNotes.json. When you run the Import-PSNote
cmdlet you can choose a catalog name. Doing so will cause the imported notes to be stored in a file with that catalogs name.
This example exports all notes to a JSON file.
Export-PSNote -All -Path C:\Export\MyPSNotes.json
This example exports the notes with the tag AD to a JSON file.
Get-PSNote -tag 'AD' | Export-PSNote -Path C:\Export\SharedADNotes.json
This example imports the contents of the file MyPSNotes.json and saves it to your personal PSNotes.json file.
Import-PSNote -Path C:\Import\MyPSNotes.json
This example imports the contents of the file SharedADNotes.json and saves it to the file ADNotes.json in the folder %APPDATA%\PSNotes
Import-PSNote -Path C:\Export\SharedADNotes.json -Catalog 'ADNotes'