Skip to content

Instantly share code, notes, and snippets.

View davidlu1001's full-sized avatar

David Lu davidlu1001

View GitHub Profile
@davidlu1001
davidlu1001 / ops.ps1
Last active June 27, 2024 06:20
Operation scripts for copy files and run commands on remote servers
## Usage Examples
#
### Execute a command on multiple remote computers
# .\ops.ps1 -ComputerName Server1, Server2 -Command "Get-Service | Where-Object {`$_.Status -eq 'Running'}"
#
### Run a script on a remote computer with arguments
# .\ops.ps1 -ComputerName Server1 -ScriptPath C:\Scripts\DiskCleanup.ps1 -ArgumentList @{DaysOld = 30; LogPath = "C:\Logs"}
#
### Copy files to multiple remote computers
# .\ops.ps1 -ComputerName Server1, Server2 -Source C:\Updates\Patch.msp -Destination C:\Temp -Recurse
@davidlu1001
davidlu1001 / setRegValues.ps1
Created June 25, 2024 22:38
Set Reg Values
# Examples
#
# Run locally with dry-run mode
#.\setRegValues.ps1 -csvFilePath ".\DNSPatternMatches.csv" -dryRun -Verbose
#
# Run locally
#.\setRegValues.ps1 -csvFilePath ".\DNSPatternMatches.csv"
#
# Run remotely
#.\setRegValues.ps1 -csvFilePath ".\DNSPatternMatches.csv" -computerNames "RemoteComputer1", "RemoteComputer2"
@davidlu1001
davidlu1001 / updateIISBindings.ps1
Last active June 25, 2024 09:21
Update IIS Bindings
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$matchPattern = "\.co\.nz",
[Parameter(Mandatory=$false)]
[string]$originalString = "dev",
[Parameter(Mandatory=$false)]
[string]$targetString = "dev2",
@davidlu1001
davidlu1001 / getRegValues.ps1
Last active June 25, 2024 09:17
Get Reg Values
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$dnsNamePattern = 'google',
[Parameter(Mandatory=$false)]
[string[]]$registryPaths = @("HKLM:\SOFTWARE\WOW6432Node\Google"),
[Parameter(Mandatory=$false)]
[string[]]$excludePaths = @("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Google\Update*"),
[Parameter(Mandatory=$false)]
[string[]]$computerNames = @("localhost"),
@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,
@davidlu1001
davidlu1001 / dnsFailover.ps1
Last active June 20, 2024 11:04
Manage DNS Failover
param(
[Parameter(Mandatory=$false)]
[string]$dnsName,
[Parameter(Mandatory=$false)]
[string]$dnsServer,
[Parameter(Mandatory=$false)]
[string]$lookupZone,
@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 / 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 / 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 / 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.