Skip to content

Instantly share code, notes, and snippets.

View SamErde's full-sized avatar
:octocat:
Writing PowerShell

Sam Erde SamErde

:octocat:
Writing PowerShell
View GitHub Profile
@SamErde
SamErde / ConnectToRunMaester.ps1
Created June 17, 2025 00:51
Connecting to M365 services to run Maester
# Open a new PowerShell session with none of the modules connected yet. PowerShell 7 is recommended.
$ModuleNames = @(
'Az.Accounts',
'ExchangeOnlineManagement',
'Microsoft.Graph.Authentication'
'MicrosoftTeams'
)
Update-Module $ModuleNames
Update-Module Maester -AllowPrerelease
@SamErde
SamErde / Get-ModuleImportOrder.ps1
Last active June 15, 2025 02:11
Get-ModuleImportOrder.ps1
function Get-ModuleImportOrder {
<#
.SYNOPSIS
Evaluates the import order of specified modules based on their versions and the location in PSModulePath.
.DESCRIPTION
This function evaluates the import order of specified modules based on their versions and the location in PSModulePath.
It uses Get-ModuleImportCandidate to determine which version of each module would be imported by Import-Module,
and then sorts them by the version of 'Microsoft.Identity.Client.dll' that is packaged with each module.
# Check if environment variables indicate running in a CI/CD environment.
$CiCdEnvironment = @(
# GitHub Actions
$env:GITHUB_ACTIONS -eq 'true',
# GitLab CI
$env:GITLAB_CI -eq 'true',
# Azure DevOps
$env:TF_BUILD -eq 'true',
# Bitbucket Pipelines
$null -ne $env:BITBUCKET_BUILD_NUMBER,
@SamErde
SamErde / commit-message-guidelines.md
Created March 19, 2025 19:13 — forked from okineadev/commit-message-guidelines.md
Copilot commit messages instructions for vscode

Paste it to settings.json:

"github.copilot.chat.commitMessageGeneration.instructions": [
  {
    "text": "Follow the Conventional Commits format strictly for commit messages. Use the structure below:\n\n```\n<type>[optional scope]: <gitmoji> <description>\n\n[optional body]\n```\n\nGuidelines:\n\n1. **Type and Scope**: Choose an appropriate type (e.g., `feat`, `fix`) and optional scope to describe the affected module or feature.\n\n2. **Gitmoji**: Include a relevant `gitmoji` that best represents the nature of the change.\n\n3. **Description**: Write a concise, informative description in the header; use backticks if referencing code or specific terms.\n\n4. **Body**: For additional details, use a well-structured body section:\n   - Use bullet points (`*`) for clarity.\n   - Clearly describe the motivation, context, or technical details behind the change, if applicable.\n\nCommit messages should be clear, informative, and professional, aiding readability and project tracking."
  }
]
@SamErde
SamErde / Get-UnsafeDynamicGroups.ps1
Last active January 6, 2025 17:30
This function retrieves all dynamic groups in Entra ID and checks if the membership rule contains any user-modifiable attributes. If it does, the group is considered unsafe.
function Get-UnsafeDynamicGroups {
<#
.SYNOPSIS
Get unsafe dynamic groups in Entra ID.
.DESCRIPTION
This function retrieves all dynamic groups in Entra ID and checks if the membership rule contains any user-modifiable attributes. If it does, the group is considered unsafe.
.EXAMPLE
Get-UnsafeDynamicGroups
@SamErde
SamErde / Out-HostColored.ps1
Created December 13, 2024 14:56 — forked from mklement0/Out-HostColored.ps1
PowerShell function that colors portions of the default host output that match given patterns.
<#
Prerequisites: PowerShell version 2 or above.
License: MIT
Author: Michael Klement <[email protected]>
DOWNLOAD, from PowerShell version 3 or above:
irm https://gist.github.com/mklement0/243ea8297e7db0e1c03a67ce4b1e765d/raw/Out-HostColored.ps1 | iex
@SamErde
SamErde / Add-DevToMyWinServer.ps1
Created October 23, 2024 03:35 — forked from bentman/Add-DevToMyWinServer.ps1
Install Dev Tools on Win Server 2022
<#
.SYNOPSIS
Script to install Dev Tools on Windows Server (tested on 2022)
.DESCRIPTION
Installs the following from multiple resources:
Microsoft.VCLibs v14.00 (github)
Microsoft.UI v2.8.6 (github)
winget-cli (dynamic version retrieval from api.github.com)
Microsoft.WindowsTerminal (dynamic version retrieval from api.github.com)
Microsoft pwsh.exe vCurrent (winget)
@SamErde
SamErde / poco.psm1
Created October 15, 2024 21:50 — forked from yumura/poco.psm1
powershell peco
# Load
Split-Path $MyInvocation.MyCommand.Path -Parent | Push-Location
Get-ChildItem poco_*.ps1 | %{. $_}
Pop-Location
function Select-Poco
{
Param
(
[Object[]]$Property = $null,
@SamErde
SamErde / MathFun.ps1
Last active September 4, 2024 15:30
A little PowerShell "math" challenge to display rows of numbers that perform sequential addition
<#
Description: Start with a row of numbers from 0-10. In 10 successive rows, automatically generate the following:
- Skip the first index, having one fewer number than the previous row
- Add together the [i] and [i-1] numbers from the previous row to get the value of [i] in the current row
The final output should look like this:
0 1 2 3 4 5 6 7 8 9 10
1 3 5 7 9 11 13 15 17 19
4 8 12 16 20 24 28 32 36
@SamErde
SamErde / Get-AadJoinInformation.ps1
Created August 17, 2023 19:40 — forked from awakecoding/Get-AadJoinInformation.ps1
Get Azure AD (Entra ID) Join Information without dsregcmd
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
public enum DSREG_JOIN_TYPE {
DSREG_UNKNOWN_JOIN = 0,
DSREG_DEVICE_JOIN = 1,
DSREG_WORKPLACE_JOIN = 2
}