Instantly share code, notes, and snippets.

View unattend.xml
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="" xmlns:xsi="">
View Parse-HibpJson.ps1
#requires -version 3
Parse-HibpJson - Checks Active Directory for matching users, outputs info as objects
Cross-checks Active Directory for matching aliases from a HIBP breach JSON file, and then
lists the matching users and which breaches they were involved in.
Designed to be output to CSV for easy consumption in Excel with one breach per column
View Get-RandomPassword.ps1
function Get-RandomPassword {
$Count = 1,
$Separator = '-'
View Create-LocalAdminUser.ps1
# The name of the account
$accountName = 'LocalAdmin'
$accountFullName = 'Local Administrator'
$accountComment = 'Backup Local Administrator Account'
# Any users listed here will be disabled by this script
$usersToDisable = 'Administrator','Guest'
# Set up some Event Log stuff
$sourceName = "$($MyInvocation.MyCommand.Name).ps1"
View Schedule-ChocoUpgradeAll.ps1
# See if choco.exe is available. If not, stop execution
$chocoCmd = Get-Command -Name 'choco' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select-Object -ExpandProperty Source
if ($chocoCmd -eq $null) { break }
# Settings for the scheduled task
$taskAction = New-ScheduledTaskAction –Execute $chocoCmd -Argument 'upgrade all -y'
$taskTrigger = New-ScheduledTaskTrigger -AtStartup
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId 'SYSTEM'
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8
View Get-PerformanceCounter.ps1
function Get-PerformanceCounter
# Get the Performance Counters from the Registry
$counters = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009' -Name 'counter' | Select-Object -ExpandProperty Counter
# Remove the last line
$counters = $counters | Select-Object -SkipLast 1
# Split the string into an array
$counters = $counters.Split([Environment]::NewLine)
View Get-WeekNumber.ps1
function Get-WeekNumber([datetime]$DateTime = (Get-Date)) {
$cultureInfo = [System.Globalization.CultureInfo]::CurrentCulture
View Get-DhcpServerLog.ps1
#requires -version 3
Get-DhcpServerLog - Reads the Windows DHCP server logs
The Windows DHCP server logs are stored in CSV format in C:\Windows\System32\dhcp
It's difficult to read these logs in Notepad due to them being in CSV format.
View Spiceworks to FreshDesk - Contacts
select distinct as email,
u.first_name || ' ' || u.last_name as name,
u.title as job_title,
u.cell_phone as mobile,
u.office_phone as phone,
u.location as time_zone,
'en' as language
from users as u
inner join tickets as t on = t.created_by
where (u.disabled is null) and ((u.first_name is not null) and (u.last_name is not null))
View Disable-OutlookAddins.ps1
# List of add-in names that ARE permitted. Everything else will be disabled
$permittedAddIns = "Redemption.Addin","WorkSiteEmailManagement.Connect","imFileSite.Connect"
# Registry paths to search
$registryPaths = "Registry::HKEY_USERS\S-1-5-21-*\Software\Microsoft\Office\Outlook\Addins",
# Build up a list of add-ins by searching the specified paths