Skip to content

Instantly share code, notes, and snippets.

View dstreefkerk's full-sized avatar

Daniel dstreefkerk

  • Sydney, Australia
View GitHub Profile
@dstreefkerk
dstreefkerk / unattend.xml
Created June 7, 2017 00:41
Australia/Sydney regional settings Unattend.xml file for Windows 10 1703
<?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="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SetupUILanguage>
<UILanguage>en-AU</UILanguage>
</SetupUILanguage>
<InputLocale>0c09:00000409</InputLocale>
<UserLocale>en-AU</UserLocale>
<SystemLocale>en-AU</SystemLocale>
@dstreefkerk
dstreefkerk / Parse-HibpJson.ps1
Last active March 10, 2022 16:59
Convert a Have I Been Pwned JSON file into CSV after cross-referencing with Active Directory
#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
@dstreefkerk
dstreefkerk / Get-RandomPassword.ps1
Last active December 20, 2018 23:36
A quick function to replicate some of the functionality of http://correcthorsebatterystaple.net/
function Get-RandomPassword {
[OutputType([string])]
Param
(
[int]
$Count = 1,
[string]
$Separator = '-'
@dstreefkerk
dstreefkerk / Create-LocalAdminUser.ps1
Last active August 23, 2021 19:34
Creates a backup local admin user with a random password. Designed for use with Microsoft LAPS. Should be run as a computer logon script.
# 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"
@dstreefkerk
dstreefkerk / Schedule-ChocoUpgradeAll.ps1
Last active March 8, 2022 20:52
PowerShell script to create a scheduled task that runs a choco upgrade all at machine startup
# 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
@dstreefkerk
dstreefkerk / Get-PerformanceCounter.ps1
Created February 18, 2016 00:19
A quick PowerShell function to extract Windows' list of performance counters and their corresponding IDs
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)
@dstreefkerk
dstreefkerk / Get-WeekNumber.ps1
Last active February 9, 2021 08:31
A simple PowerShell function to return the week number for a given date using the current globalisation culture.
# Removed my original snippet. See comments below from Bart.
# The below example is courtesy of Bart.
function Get-ISO8601Week {
Param(
[datetime]$DT = (Get-Date)
)
<#
First create an integer(0/1) from the boolean,
"Is the integer DayOfWeek value greater than zero?".
Then Multiply it with 4 or 6 (weekrule = 0 or 2) minus the integer DayOfWeek value.
@dstreefkerk
dstreefkerk / Get-DhcpServerLog.ps1
Last active December 12, 2022 06:58
A basic function to read the DHCP logs locally on a Windows server, and output them in a usable format.
#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.
@dstreefkerk
dstreefkerk / Spiceworks to FreshDesk - Contacts
Created July 9, 2015 00:38
SQLite query to extract users from Spiceworks' DB for tickets created in the past 2 years and get it into the format required by FreshDesk for contact import via CSV
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))
@dstreefkerk
dstreefkerk / Disable-OutlookAddins.ps1
Created July 7, 2015 02:51
Disable all Outlook add-ins except for a specified list
# 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