Skip to content

Instantly share code, notes, and snippets.

View SweetAsNZ's full-sized avatar
🏠

Tim West SweetAsNZ

🏠
  • Sweet As Chocolate
  • Auckland, New Zealand
  • 18:07 (UTC +13:00)
View GitHub Profile
@SweetAsNZ
SweetAsNZ / Get-WindowsFirewallLog.ps1
Created January 29, 2026 02:41
Retrieves entries from the Windows Firewall log based on specified criteria e.g. Drops From an IP Address, Port, Exclude String
function Get-WindowsFirewallLog {
<#
.SYNOPSIS
Retrieves entries from the Windows Firewall log based on specified criteria.
.DESCRIPTION
This function reads the Windows Firewall log file and filters entries based on the provided string.
.PARAMETER Action
The firewall action to filter by. Valid values are 'Drop', 'Allow', or 'All'.
.PARAMETER Direction
The traffic direction to filter by. Valid values are 'Inbound', 'Outbound', or 'All'.
@SweetAsNZ
SweetAsNZ / Get-ExchangeLogFileRequired.ps1
Created January 29, 2026 02:00
Checks if log files are required for database recovery/backups for a specified Exchange mailbox database.
function Get-ExchangeLogFileRequired {
<#
.SYNOPSIS
Checks if log files are required for database recovery/backups for a specified Exchange mailbox database.
.DESCRIPTION
This function uses the eseutil command to check the header of the specified Exchange mailbox database file
to determine if any log files are required for database recovery or backups.
.PARAMETER DBName
The name of the Exchange mailbox database to check.
.EXAMPLE
@SweetAsNZ
SweetAsNZ / Get-ADUserAndGroupADSIsearcher.ps1
Last active January 28, 2026 22:37
Retrieves Active Directory user and group information using ADSISearcher
function Get-ADUserAndGroupADSIsearcher {
<#
.SYNOPSIS
Retrieves Active Directory user and group information using ADSISearcher.
.DESCRIPTION
This function searches for a user in Active Directory and retrieves their group memberships.
.EXAMPLE
Get-ADUserAndGroupADSIsearcher -UserName "Tim West"
.EXAMPLE
Get-ADUserAndGroupADSIsearcher -samAccountName "JDoe" | Select-String "SERVER1-RemoteDesktopUsers"
@SweetAsNZ
SweetAsNZ / Get-WindowsFirewallRules.ps1
Last active January 28, 2026 21:06
Retrieves the Windows Firewall rules based on Local Port, Name, Remote IP from the local store and group policy.
function Get-WindowsFirewallRules {
<#
.SYNOPSIS
Retrieves the current Windows Firewall rules based on Local Port, Name, Remote IP.
.DESCRIPTION
This function fetches and displays the current firewall rules configured on the Windows system.
.PARAMETER LocalPort
The local port number to filter the firewall rules.
.PARAMETER Name
The name of the firewall rule to filter.
@SweetAsNZ
SweetAsNZ / Set-FirewallLogFile.ps1
Last active January 28, 2026 01:47
Sets up the Windows Firewall log file and folder with the correct permissions and creates the log files. Then prompts to reboot.
Function Set-FirewallLogFile {
<#
.SYNOPSIS
Sets up the Windows Firewall log file with the correct permissions.
.DESCRIPTION
This function creates a Windows Firewall log file at the specified location and sets the appropriate permissions for system services and administrators.
Requires Administrator privileges. System reboot is required for changes to take effect.
Added NetSH commands to configure firewall logging as overkill just in case.
Script works for standard and .old log files after reboot
@SweetAsNZ
SweetAsNZ / Set-UserPassword.ps1
Created January 26, 2026 20:24
Set an AD Users Password
function Set-UserPassword {
<#
.SYNOPSIS
Change your AD password, use SAMAccount Name to change another users password
.DESCRIPTION
Change your AD password, use SAMAccount Name to change another users password
.EXAMPLE
Set-UserPassword
.EXAMPLE
Set-UserPassword -SAMAccountName 'jsmith'
@SweetAsNZ
SweetAsNZ / Get-UsersPasswordPolicy.ps1
Last active January 19, 2026 19:54
Gets the effective password policy for a user, including fine-grained password policies if applied. Returns user password status along with policy requirements.
function Get-UsersPasswordPolicy {
<#
.SYNOPSIS
Retrieves password policy settings for a user from Active Directory.
.DESCRIPTION
Gets the effective password policy for a user, including fine-grained password policies if applied.
Returns user password status along with policy requirements.
.PARAMETER UserName
The username (SamAccountName) to query. Defaults to the current user.
.EXAMPLE
@SweetAsNZ
SweetAsNZ / Invoke-ExchangeDatabaseFailover.ps1
Last active January 19, 2026 21:41
Initiates a failover of an Exchange mailbox database to another server within its Database Availability Group (DAG). Waits if too may failovers have happened. Optionally choose the server or by default take the first one available
function Invoke-ExchangeDatabaseFailover {
<#
.SYNOPSIS
Initiates a failover of an Exchange mailbox database to another server within its Database Availability Group (DAG).
.DESCRIPTION
This function allows administrators to trigger a failover of a specified Exchange mailbox database to another server
within its Database Availability Group (DAG). Optionally, a target server can be specified for the failover.
.PARAMETER DatabaseName
The name of the Exchange mailbox database to failover.
.PARAMETER TargetServer
@SweetAsNZ
SweetAsNZ / Get-WindowsInfo.ps1
Last active January 30, 2026 01:34
Multiple Functions to get various Windows system information. Get-DNSServers, Get-DNS, Get-Gateway, Get-GW, Get-IP, Get-SubnetMask, Get-MACAddress, Get-MAC, Get-UpTime, Get-DiskSpace, Get-MappedDrives, Test-Gateway, Test-GW, Get-FreeSpace, Get-Proxy, Show-Proxy, Get-Routes, Touch, Get-MyExternalIP, Get-NetBIOS, Set-NetBIOS
<#
.SYNOPSIS
A collection of functions to retrieve various Windows system information such as DNS servers, gateway, IP addresses, subnet masks, MAC addresses, uptime, disk space, mapped drives, and more.
.DESCRIPTION
This script contains multiple functions that can be used to gather different pieces of information about a Windows
system. Each function is designed to perform a specific task and can be called independently.
.PARAMETER
N/A
.EXAMPLE
Get-DNSServers
@SweetAsNZ
SweetAsNZ / Get-VCRunTime.ps1
Last active December 10, 2025 01:45
Gets the latest/installed Visual C++ RunTime with PowerShell
function Get-VisualCRuntime {
<#
.SYNOPSIS
Get Visual Studio Latest Installed RunTime
.EXAMPLE
Get-VisualCRuntime
#>
[CmdletBinding()]
Param(
[switch]$Latest # See here for latest https://aka.ms/vc14/vc_redist.x64.exe, https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170