Skip to content

Instantly share code, notes, and snippets.

View adbertram's full-sized avatar

Adam Bertram adbertram

View GitHub Profile
@adbertram
adbertram / Select-Item.ps1
Last active March 15, 2024 12:28
An interactive PowerShell function to select items from a collection based on the first letter
function SelectItem {
<#
.SYNOPSIS
Selects an item from a provided list based on keyboard input.
.DESCRIPTION
The SelectItem function allows the user to select an item from a given list of strings by typing the first letter of the
item. The function iterates through the items that start with the given letter, allowing the user to press the same letter
repeatedly to cycle through the options. Selection is confirmed with the Enter key.
@adbertram
adbertram / timer.ps1
Created September 7, 2023 20:44
PowerShell Timer with Real-Time Counting
# Initialize timer variables
$timerStart = $null
$elapsedTime = $null
# Function to display elapsed time
function DisplayElapsedTime {
param (
[ref]$startTime,
[ref]$elapsedTime
)
#ifndef EMPLOYEE_SALARY_SLIP_H_INCLUDED
#define EMPLOYEE_SALARY_SLIP_H_INCLUDED
#include <iostream>
#include <string>
#include "Employee.h"
using namespace std;
class EmployeeSalarySlip : public Employee {
###################################################
# This is an associated snippet on learning Azure Functions by Jeff Brown at:
# https://adamtheatuomator.com/azure-functions-tutorial
###################################################
# The function URL appends the function name with a question mark and a code. This code is the function key and
# authenticates to the function for execution. Without this key, you would not be able to trigger the function.
# This key provides security so not just anyone can start the function.
$functionKey = '' ## Fill this in from the Get function URL page
$functionAppName = 'ata-powershell-functions'
###################################################
# This is an associated snippet on learning Azure Functions by Jeff Brown at:
# https://adamtheatuomator.com/azure-functions-tutorial
###################################################
## The using statement imports the System.Net namespace, and param() defines the function's parameters.
using namespace System.Net
## Input bindings are passed in via param block.
## The *$Request* parameter contains the information passed to the function during the HTTP request. This information includes the request headers, request body, HTTP method, parameters, and URL of the request.
function Set-RegistryValueForAllUsers {
<#
.SYNOPSIS
This function uses Active Setup to create a "seeder" key which creates or modifies a user-based registry value
for all users on a computer. If the key path doesn't exist to the value, it will automatically create the key and add the value.
.EXAMPLE
PS> Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = 'Setting'; 'Type' = 'String'; 'Value' = 'someval'; 'Path' = 'SOFTWARE\Microsoft\Windows\Something'}
This example would modify the string registry value 'Type' in the path 'SOFTWARE\Microsoft\Windows\Something' to 'someval'
for every user registry hive.
$RegUninstallPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
)
$VersionsToKeep = @('Java 8 Update 261')
Get-CimInstance -ClassName 'Win32_Process' | Where-Object {$_.ExecutablePath -like '*Program Files\Java*'} |
Select-Object @{n='Name';e={$_.Name.Split('.')[0]}} | Stop-Process -Force
#Requires -RunAsAdministrator
<#
.SYNOPSIS
This parses the native netstat.exe's output using the command line "netstat -anb" to find
all of the network ports in use on a local machine and all associated processes and services
.NOTES
Created on: 2/15/2015
Created by: Adam Bertram
Filename: Get-LocalPort.ps1
#requires -Module ActiveDirectory
$dnsServer = '' ## This is the server name as a NETBIOS or FQDN
$OutputFilePath = 'C:\DNSDebugLogSummary.csv' ## The CSV file that will be created
## The log file you specified in the debug logging dialog box
$DnsDebugLogFilePath = "\$dnsServer\c$\DnsDebugLog.log"
## Find all of the DNS server IPs in the current domain
$DnsServerIPs = ((Get-ADDomain).ReplicaDirectoryServers | Resolve-DnsName).IPAddress
#Requires -Version 3
<#
.SYNOPSIS
This script checks a ConfigMgr site backup to ensure success and performs various post-backup functions that
back up other critical data that the built-in ConfigMgr site backup task does not.
.DESCRIPTION
This script checks any previous backup attempt ran within the last hour of this script running for a
a successful run if backup check is selected. It assumes you also have SSRS installed on the site DB server
and backs up both SSRS databases, exports out the SSRS encryption keys, backs up the export file and the