Skip to content

Instantly share code, notes, and snippets.

View aldrichtr's full-sized avatar

Tim Aldrich aldrichtr

View GitHub Profile
<#
If you create enums and/or custom attributes and want to reuse them, you would (or at least, I did) think that they should go into psm1 module files and be included in other modules via the NestedModules line of the module manifest.
BUT YOU WOULD BE (or at least, I was) WRONG!
Instead, create them in .ps1 script files and add them to the ScriptsToProcess line of the module manifest.
And if you use the enum directly in Pester tests, you will need to run the enum script file there, too, as they do not persist between scripts (as noted here: https://tfl09.blogspot.com/2014/11/enums-in-powershell-v5.html).
That said, if you follow this advice for enums (is it that the enums are in ScriptsToProcess, or anything? I haven't tested), you may need to refactor classes into THEIR own psm1 files. But in so doing, you may break Get-Help and intellisense for functions that take objects of those classes as parameters. At which point you may wind up with all the Enums and Classes back in the main psm1 file(s).
By way of
# Set your PowerShell execution policy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
function Invoke-ComputerSetup {
[CmdletBinding(DefaultParameterSetName='Parameter Set 1',
SupportsShouldProcess=$true,
PositionalBinding=$false,
@aldrichtr
aldrichtr / user-profile.psm1
Created June 30, 2023 20:15
PowerShell functions to create a new user profile
<#
.Synopsis
Rough PS functions to create new user profiles
.DESCRIPTION
Call the Create-NewProfile function directly to create a new profile
.EXAMPLE
Create-NewProfile -Username 'testUser1' -Password 'testUser1'
.NOTES
Created by: Josh Rickard (@MS_dministrator) and Thom Schumacher (@driberif)
@aldrichtr
aldrichtr / Replace-Tokens.ps1
Created February 23, 2023 23:39 — forked from niclaslindstedt/Replace-Tokens.ps1
PowerShell script to replace tokens in a file. Useful for DevOps when you have a template config file that you wish to insert real values into.
<#
.SYNOPSIS
Replace tokens in a file with values.
.DESCRIPTION
Finds tokens in a given file and replace them with values. It is best used to replace configuration values in a release pipeline.
.PARAMETER InputFile
The file containing the tokens.
@aldrichtr
aldrichtr / Alacritty.yml
Created February 13, 2023 02:54 — forked from SuperMatt/Alacritty.yml
Dark+ V2 Terminal Theme
primary:
background: '#181818'
foreground: '#C7C7C7'
normal:
black: '#000000'
red: '#CD3131'
green: '#0DBC79'
yellow: '#E5E510'
blue: '#2472C8'
magenta: '#BC3FBC'
@aldrichtr
aldrichtr / CellFindingVisitor.cs
Created December 27, 2022 22:17 — forked from SQLvariant/CellFindingVisitor.cs
PowerShell AST visitor to break up a file by comments
using System;
using System.Collections.Generic;
using System.Management.Automation.Language;
public class ScriptExtent : IScriptExtent
{
private readonly IScriptPosition _start;
private readonly IScriptPosition _end;
@aldrichtr
aldrichtr / PSStyleFileInfoTools.ps1
Created December 19, 2022 16:31 — forked from jdhitsolutions/PSStyleFileInfoTools.ps1
A set of functions for exporting and importing FileInfo settings from $PSStyle in PowerShell 7.2.
#requires -version 7.2
<#
These commands can be used to export FileInfo settings from $PSStyle and
then import them in another session. You might use the import command in
your PowerShell profile script. The file must be a json file.
#>
Function Export-PSStyleFileInfo {
[cmdletbinding(SupportsShouldProcess)]
Param(
@aldrichtr
aldrichtr / DisplayFonts.ps1
Created November 29, 2022 20:07 — forked from matthewjberger/DisplayFonts.ps1
PowerShell Font Listing
# From https://technet.microsoft.com/en-us/library/ff730944.aspx
# This will open an internet explorer window that will display all installed windows font names in their corresponding font.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objFonts = New-Object System.Drawing.Text.InstalledFontCollection
$colFonts = $objFonts.Families
$objIE = New-Object -com "InternetExplorer.Application"
$objIE.Navigate("about:blank")
$objIE.ToolBar = 0
@aldrichtr
aldrichtr / connect.ps1
Created November 29, 2022 18:58 — forked from codebykyle/connect.ps1
Windows Terminal Split Pane Powershell Script - v2
using namespace System.Collections.Generic
# Encapsulate an arbitrary command
class PaneCommand {
[string]$Command
PaneCommand() {
$this.Command = "";
}
@aldrichtr
aldrichtr / .gitconfig
Created November 29, 2022 18:46 — forked from xiongjia/.gitconfig
Some useful Git aliases that I use every day #conf #git
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"