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.
$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
@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
)
$resourceGoupName = 'skylinespsdemo'
$azureRegion = 'East US'
$vmName = 'MYVM'
#region Create the resource group
New-AzResourceGroup -Name $resourceGoupName -Location $azureRegion
#endregion
#region Create the vNet for the VM
$newSubnetParams = @{
#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 {
#region Ensure the WinRm service is running
Set-Service -Name "WinRM" -StartupType Automatic
Start-Service -Name "WinRM"
#endregion
#region Enable PS remoting
if (-not (Get-PSSessionConfiguration) -or (-not (Get-ChildItem WSMan:\localhost\Listener))) {
Enable-PSRemoting -SkipNetworkProfileCheck -Force
}
#endregion
## Ensure you're using 2.0+ of the azurevm provider to get the azurerm_windows_virtual_machine reosurce and
## the other resources and capabilities
provider "azurerm" {
version = "2.0.0"
features {}
}
## Create an Azure resource group using the value of resource_group and the location of the location variable
## defined in the terraform.tfvars file.
resource "azurerm_resource_group" "monolithRG" {
"Pester - Describe block (Unit Test, Exported Function)": {
"prefix": "descu",
"body": [
"describe '${name}' {",
"",
"\t$$commandName = '${name}'",
"",
"\tcontext 'Help' {",
"\t\t",
#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
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.