Instantly share code, notes, and snippets.

View Parse-HibpJson.ps1
#requires -version 3
<#
.SYNOPSIS
Parse-HibpJson - Checks Active Directory for matching users, outputs info as objects
.DESCRIPTION
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 {
[OutputType([string])]
Param
(
[int]
$Count = 1,
[string]
$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
$cultureInfo.Calendar.GetWeekOfYear($DateTime,$cultureInfo.DateTimeFormat.CalendarWeekRule,$cultureInfo.DateTimeFormat.FirstDayOfWeek)
}
View Get-DhcpServerLog.ps1
#requires -version 3
<#
.SYNOPSIS
Get-DhcpServerLog - Reads the Windows DHCP server logs
.DESCRIPTION
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 u.email 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 u.id = 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",
"Registry::HKEY_USERS\S-1-5-21-*\Software\Wow6432Node\Microsoft\Office\Outlook\Addins",
"HKLM:\Software\Wow6432Node\Microsoft\Office\Outlook\Addins",
"HKLM:\Software\Microsoft\Office\Outlook\Addins"
# Build up a list of add-ins by searching the specified paths
View Get-ChicagoCrimes.ps1
# Get the data, convert it to JSON
$jsonData = Invoke-WebRequest "https://data.cityofchicago.org/resource/ijzp-q8t2.json" | ConvertFrom-Json
# Filter our data set down to only the last month's crimes. Note that the data feed has a built-in lag of 7 days
$lastMonthsData = $jsonData | Where-Object {($_.date | get-date) -gt ((get-date).AddMonths(-1))}
# Show results, allowing user to select categories first and then view individual crimes
$lastMonthsData | Group-Object -Property primary_type | Sort-Object Count -Descending | Select-Object Name,Count,Group | Out-GridView -Title "Select a category (or multiple) to view details" -OutputMode Multiple | Select-Object -ExpandProperty Group | select primary_type,description,location_description,date,latitude,longitude,block,domestic,arrest,case_number | Sort-Object date -Descending | Out-GridView -Title "Crime Details"