Skip to content

Instantly share code, notes, and snippets.

View davidlu1001's full-sized avatar

David Lu davidlu1001

View GitHub Profile
@davidlu1001
davidlu1001 / smb.ps1
Last active March 5, 2024 03:09
SMB script to check/enable/disable
param(
[ValidateSet("Check", "Enable", "Disable")]
[string]$Action = "Check",
[ValidateSet("SMB1", "SMB2", "All")]
[string]$SMBVersion = "All"
)
function Check-SMBStatus {
Write-Host "Checking SMB protocol status..."
@davidlu1001
davidlu1001 / Get-EventLogs.ps1
Created March 27, 2024 01:44
Get EventLogs
<#
.SYNOPSIS
Retrieves Windows event logs from local or remote servers based on specified filters.
.DESCRIPTION
This script queries Windows event logs from specified servers, filtering by log name, provider name, event level, and text match within events. Results can be displayed in the console or exported to a CSV file.
.PARAMETER Servers
Specifies an array of server names from which to query the event logs.
param(
[string[]]$Servers = @($env:COMPUTERNAME), # Defaults to the local computer
[int]$DaysAgo = 1,
[string[]]$LogNames = @("Application", "System"),
[ValidateSet("Critical", "Error", "Warning", "Information", "Verbose")]
[string[]]$LogLevels = @("Critical", "Error", "Warning"),
[string]$OutputHTML = "EventLogReport.html"
)
# Ensure PSWriteHTML is available
@davidlu1001
davidlu1001 / getCNAME.ps1
Last active May 6, 2024 05:20
Get DNS CNAMES recursively for specified Servers
param (
[Parameter(Mandatory = $true)]
[string]$dnsServer,
[Parameter(Mandatory = $true)]
[string[]]$lookupZones,
[Parameter(Mandatory = $true)]
[string[]]$specificServerNames
)
function Get-CNameRecords {
@davidlu1001
davidlu1001 / manageServiceRecovery.ps1
Last active May 17, 2024 00:11
Get/Set Service Recovery Settings
<#
.SYNOPSIS
Manages the recovery options of Windows services.
.DESCRIPTION
This script can retrieve or set the recovery options of specified Windows services using the `sc.exe` utility. It supports operations on multiple services at once by accepting service names with wildcards or regex patterns. The script allows for configuring how the service responds to first, second, and subsequent failures.
.PARAMETER ServiceNames
Array of service names or patterns to match against existing services.
@davidlu1001
davidlu1001 / checkRegValues.ps1
Last active June 11, 2024 22:44
Check REG value contains string
param(
[string]$dnsNamePattern = '.*\.co\.nz$' # Regex to match DNS names ending with '.co.nz'
)
# Define the registry paths to check
$registryPaths = @("HKLM:\SOFTWARE", "HKLM:\SYSTEM", "HKLM:\SECURITY")
# Create an array to store the results
$results = @()
@davidlu1001
davidlu1001 / CheckAndAddCnames.ps1
Last active June 11, 2024 07:30
CheckAndAddCnames.ps1
param(
[Parameter(Mandatory = $false)]
[string[]]$CnameList,
[Parameter(Mandatory = $false)]
[string]$CnameListFilePath,
[Parameter(Mandatory = $true)]
[string]$TargetHostname,
@davidlu1001
davidlu1001 / getServiceExecPath.ps1
Last active June 17, 2024 02:12
Get Service Executable Path
param(
[string]$ServiceNamePattern # Input parameter to match service names using regex
)
# Get all services matching the pattern
$services = Get-Service | Where-Object { $_.Name -match $ServiceNamePattern }
# Iterate through each matching service
foreach ($service in $services) {
try {
@davidlu1001
davidlu1001 / dnsFailover.ps1
Last active March 20, 2025 20:05
Manage DNS Failover
[CmdletBinding()]
param(
[Parameter(Mandatory=$false)]
[ValidateSet("Dev", "Prod")]
[string]$Env = "Dev",
[Parameter(Mandatory=$false)]
[string]$dnsServer,
[Parameter(Mandatory=$false)]
@davidlu1001
davidlu1001 / setCNameTTL.ps1
Last active June 20, 2024 11:46
Set CName TTL
param(
[Parameter(Mandatory=$false)]
[string]$dnsServer,
[Parameter(Mandatory=$false)]
[string]$lookupZone,
[Parameter(Mandatory=$false)]
[string[]]$cnameRecords,