SkillAgentSearch skills...

PowerShell

PowerShell Core Profile Directory

Install / Use

/learn @jimbrig/PowerShell

README

PowerShell

My customized powershell (core) profile directory ~/Documents/PowerShell (or ~/Documents/OneDrive/PowerShell).

See the Changelog for details on this repository's development over time.

<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Table of Contents

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Overview

In this repository there are the following profile files:[^1]

Notes:

Core $PROFILE

For profile.ps1 (main profile):

Simply dot sources each top-level *.ps1 file from the Profile directory:

<details><summary>🔎 View Code</summary> <p> <!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./profile.ps1) --> <!-- The below code snippet is automatically added from ./profile.ps1 -->
#Requires -Version 7

# Version: 0.1.0

# ----------------------------------------------------
# Current User, All Hosts Powershell Core v7 $PROFILE:
# ----------------------------------------------------

$psfiles = Join-Path (Split-Path -Parent $profile) "Profile" | Get-ChildItem -Filter "*.ps1"
ForEach ($file in $psfiles) { . $file }
<!-- MARKDOWN-AUTO-DOCS:END --> </p> </details>

The Profile Directory

All features of the $PROFILE come from the Profile directory:

➜ ~\OneDrive\Documents\PowerShell :: git(main)                        01:39:05  
➜ tree /F /A Profile
Folder PATH listing
Volume serial number is 4879-37CA
C:\USERS\JIMMY\ONEDRIVE\DOCUMENTS\POWERSHELL\PROFILE
|   aliases.ps1
|   completion.ps1
|   functions.ps1
|   modules.ps1
|   options.ps1
|   prompt.ps1
|   
+---aliases
|       aliases-export.ps1
|       
+---completions
|       aws.ps1
|       choco.ps1
|       docker.ps1
|       dotnet.ps1
|       gh-cli.ps1
|       git-cliff.ps1
|       s-search.ps1
|       scoop.ps1
|       spotify.ps1
|       winget.ps1
|       yq.ps1
|       
\---functions
        Get-AdminRights.ps1
        Get-NetAccelerators.ps1
        Get-NetFramework.ps1
        Get-RandomAbout.ps1
        Get-RandomHelp.ps1
        Launch-AzurePortal.ps1
        Module-Helpers.ps1
        System-Functions.ps1
        Test-WiFi.ps1

Options

See options.ps1.

  • Trust PSGallery
  • Setup some $PSDefaultParameterValues
  • Set some PSReadLine Handlers
<details><summary>🔎 View Code</summary> <p> <!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./Profile/options.ps1) --> <!-- The below code snippet is automatically added from ./Profile/options.ps1 -->
# Trust PSGallery
$galleryinfo = Get-PSRepository | Where-Object { $_.Name -eq "PSGallery" }
if (-not($galleryinfo.InstallationPolicy.Equals("Trusted"))) { Set-PSRepository -Name PSGallery -InstallationPolicy Trusted }

# Default Parameters
$PSDefaultParameterValues = @{
	"Update-Module:Confirm"     = $False;
	"Update-Module:Force"       = $True;
	"Update-Module:Scope"       = "CurrentUser";
	"Update-Module:ErrorAction" = "SilentlyContinue";
	"Update-Help:Force"         = $True;
	"Update-Help:ErrorAction"   = "SilentlyContinue";
}

# Set PSReadLineOptions's (Beta Version Required):
Set-PSReadLineOption -PredictionSource History -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Set-PSReadLineOption -PredictionViewStyle ListView -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Set-PSReadLineOption -EditMode Windows
<!-- MARKDOWN-AUTO-DOCS:END --> </p> </details>

Prompt

  • Set prompt theme via oh-my-posh
  • Output useful startup information

From prompt.ps1:

<details><summary>🔎 View Code</summary> <p> <!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./Profile/prompt.ps1) --> <!-- The below code snippet is automatically added from ./Profile/prompt.ps1 -->
# Prompt
If (Get-Command oh-my-posh -ErrorAction SilentlyContinue) {
    oh-my-posh init pwsh --config $ENV:POSH_THEMES_PATH\wopian.omp.json | Invoke-Expression
}

# Write Current Version and Execution Policy Details:
Write-Host "PowerShell Version: $($psversiontable.psversion) - ExecutionPolicy: $(Get-ExecutionPolicy)" -ForegroundColor yellow

# ZLocation must be after all prompt changes:
Import-Module ZLocation
Write-Host -Foreground Green "`n[ZLocation] knows about $((Get-ZLocation).Keys.Count) locations.`n"
<!-- MARKDOWN-AUTO-DOCS:END --> </p> </details>

Functions

My suite of custom functions to be loaded for every PowerShell session:

  • Search functions via zquestz/s

  • Google Calendar functions via gcalcli

  • Directory listing functions for lsd

  • System Utility Functions

  • Symlinking Functions

  • Network Utilities

  • Programs

  • PowerShell helpers

  • Remoting

  • Chocolatey

  • R and RStudio

  • GitKraken

  • See functions.ps1:

<details><summary>🔎 View Code</summary> <p> <!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./Profile/functions.ps1) --> <!-- The below code snippet is automatically added from ./Profile/functions.ps1 -->
# ----------
# Launchers
# ----------

Function Open-Todoist { Start-Process -PassThru 'C:\Users\jimmy\AppData\Local\Programs\todoist\Todoist.exe' }

Function Open-GitHub { Start-Process -PassThru 'https://github.com/' }

Function Open-Docker { Start-Process -PassThru 'C:\Program Files\Docker\Docker\frontend\Docker Desktop.exe' }

Function Open-RProject { Rscript -e 'jimstools::open_project()' }

# ---------------------------------
# PowerShell Core Profile Functions
# ---------------------------------

Function Remove-OldModules {

  Write-Host 'this will remove all old versions of installed modules'
  Write-Host 'be sure to run this as an admin' -ForegroundColor yellow
  Write-Host '(You can update all your Azure RM modules with update-module Azurerm -force)'

  $mods = Get-InstalledModule

  foreach ($mod in $mods) {
    Write-Host "Checking $($mod.name)"
    $latest = Get-InstalledModule $mod.name
    $specificmods = Get-InstalledModule $mod.name -AllVersions
    Write-Host "$($specificmods.count) versions of this module found [ $($mod.name) ]"
  
    foreach ($sm in $specificmods) {
      if ($sm.version -ne $latest.version) {
        Write-Host "uninstalling $($sm.name) - $($sm.version) [latest is $($latest.version)]"
        $sm | Uninstall-Module -Force
        Write-Host "done uninstalling $($sm.name) - $($sm.version)"
        Write-Host '    --------'
      }
	
    }
    Write-Host '------------------------'
  }
  Write-Host 'done'

}

Function Update-ProfileModules {

  $modpath = ($env:PSModulePath -split ";")[0]
  $ymlpath = "$modpath\modules.yml"
  $mods = (Get-ChildItem $modpath -Directory).Name
  ConvertTo-Yaml -Data $mods -OutFile $ymlpath -Force

  # Set-Location "$HOME\Documents"
  # git pull
  # git add PowerShell/Modules/**
  # git commit -m "config: Updated modules configurations"
  # git-cliff -o "$HOME\Documents\CHANGELOG.md"
  # git add CHANGELOG.md
  # git commit -m "doc: update CHANGELOG.md for added modules"
  # git push

}

# ----------------------
# System Utilities
# ----------------------

# Troubleshooters

# Hardware Troubleshooter (unavailable in settings)
${function:Invoke-HardwareDiagnostic} = { & msdt.exe -id DeviceDiagnostic }
${function:Invoke-NetworkDiagnostic} = { & msdt.exe -id NetworkDiagnosticsNetworkAdapter }
${function:Invoke-SearchDiagnostic} = { & msdt.exe -id SearchDiagnostic }
${function:Invoke-WindowsUpdateDiagnostic} = { & msdt.exe -id WindowsUpdateDiagnostic }
${function:Invoke-MaintenanceDiagnostic} = { & msdt.exe -id MaintenanceDiagnostic }

# Check Disk
${function:Check-Disk} = { & chkdsk C: /f /r /x }

# Update Environment
${function:Update-Environment} = {
  $env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
  Write-Host -ForegroundColor Green "Sucessfully Refreshed Environment Variables For powershell.exe"
}

# Clean System
${function:Clean-System} = {
  Write-Host -Message 'Emptying Recycle Bin' -ForegroundColor Yellow
  (New-Object -ComObject Shell.Application).Namespace(0xA).items() | ForEach-Object { Remove-Item $_.path -Recurse -Confirm:$false }
  Write-Host 'Removing Windows %TEMP% files' -ForegroundColor Yellow
  Remove-Item c:\Windows\Temp\* -Recurse -Force -ErrorAction SilentlyContinue
  Write-Host 'Removing User %TEMP% files' -ForegroundColor Yellow
  Remove-Item “C:\Users\*\Appdata\Local\Temp\*” -Recurse -Force -ErrorAction SilentlyContinue
  Write-Host 'Removing Custome %TEMP% files (C:/Temp and C:/tmp)' -ForegroundCol
View on GitHub
GitHub Stars24
CategoryDevelopment
Updated2mo ago
Forks4

Languages

PowerShell

Security Score

80/100

Audited on Jan 19, 2026

No findings