Skip to content

griffeth-barker/PSProfileWatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSProfileWatcher

A simple script module for checking if there were changes to your Powershell profile between sessions.

ℹ️ NOTE
This module is exploring development and may have frequent breaking changes. Please be sure to read the changelog and consider this module to NOT be production-ready.

Installation

PowerShell Gallery

PSGallery Version PSGallery Downloads

You can install the module from the PowerShell Gallery.

Install-PSResource -Name PSProfileWatcher -Repository PSGallery

# Or, install using PowerShellGet module, which is no longer in active development.
# Install-Module -Name PSProfileWatcher -Repository PSGallery

Download and Import

Alternatively, you can download the latest release, extract the archive, then import the module.

Expand-Archive -Path "$($env:HOME)\Downloads\PSProfileWatcher-0.2.0.tar.gz"
Import-Module ".\PSProfileWatcher-0.2.0\PSProfileWatcher"

Getting Started

Explore Functions

Once you've imported the module, get started by using Get-Command -Module PSProfileWatcher to discover the functions, or by reading the docs. Some common scenarios are covered below for your convenience.

Common Scenarios

Enable profile snapshot checking during profile load

This will prepend the contents of your PowerShell profile with the requisite commands for checking the profile.

Register-PSProfileSnapshotTest

Create your first profile snapshot

Creating a snapshot is as simple as this.

New-PSProfileSnapshot

Optionally, you can name your snapshot and include notes.

New-PSProfileSnapshot -Name "backup" -Notes "Before major changes"

List profile snapshots

To get a list of the available profile snapshots:

Get-PSProfileSnapshot

Remove a specific snapshot

Remove-PSProfileSnapshot -Name "Example"

You can also get a specific snapshot and pipe it to the removal function.

Get-PSProfileSnapshot | Where-Object { $_.GUID -eq '00000000-0000-0000-0000-000000000000' } | Remove-PSProfileSnapshot

Cleaning up snapshots

You can remove any profile snapshots except the most recent X snapshots.

Remove-PSProfileSnapshot -KeepLast 5

You can also remove any profile snapshots that are older than X days.

Remove-PSProfileSnapshot -OlderThan 7

If you look in your profile directory and see a large number of files hanging around, they could be orphaned. You can clean those up like so:

Clear-PSProfileSnapshotOrphans

Restoring a snapshot

If you want to go back to a specific snapshot, you can do that by name, GUID, or by selecting the first/last, etc..

Restore-PSProfileSnapshot -GUID '00000000-0000-0000-0000-000000000000'
Restore-PSProfileSnapshot -Name 'Example'
Get-PSProfileSnapshot | Select-Object -First 1 | Restore-PSProfileSnapshot

Check current profile against a snapshot

You can compare two snapshots against each other by name or GUID.

Compare-PSProfileSnapshot -Name1 'Example' -Name2 'Baseline'
Compare-PSProfileSnapshot -GUID1 '00000000-0000-0000-0000-000000000000' -GUID2 '00000000-0000-0000-0000-000000000000'

You can also test the hash of your current profile against the hash of the last snapshot.

Test-PSProfileSnapshot

If you've enabled profile checking with the Register-PSProfileSnapshotTest function, then this will happen each time your profile loads.

Disable profile snapshot checking

Finally, if you no longer want your profile checked at load:

Unregister-PSProfileSnapshotTest

This will remove the related code from the beginning of your profile.

Feedback

Please ⭐ star this repository if it is helpful. Constructive feedback is always welcome, as are pull requests. Feel free to open an issue on the repository if needed.