Skip to content

Instantly share code, notes, and snippets.

View davidlu1001's full-sized avatar

David Lu davidlu1001

View GitHub Profile
@davidlu1001
davidlu1001 / Get-EventLogSummary.ps1
Created July 23, 2024 02:13
Get EventLog Summary with latest message
<#
.SYNOPSIS
Retrieves and summarizes Event Log data from local or remote machines.
.DESCRIPTION
This script retrieves Event Log data from specified machines, groups the events,
and provides a summary including count and the latest message for each group.
.PARAMETER ComputerName
Specifies the target computers. Default is the local machine.
@davidlu1001
davidlu1001 / manage_vm_snapshot.py
Last active July 22, 2024 10:58
Manage VM Snapshot
import argparse
import time
from playwright.sync_api import Playwright, sync_playwright, expect, TimeoutError
import logging
import sys
import os
from dotenv import load_dotenv
import configparser
from typing import List, Tuple, Dict, Any
#from tqdm import tqdm
@davidlu1001
davidlu1001 / manageVMSnapshots.ps1
Created July 9, 2024 10:10
Manage VM Snapshots
<#
.SYNOPSIS
Automates snapshot management for virtual machines.
.DESCRIPTION
This script automates the process of creating and managing snapshots for virtual machines
in a web-based management interface. It is compatible with PowerShell V5 and does not rely on external WebDriver dependencies.
.NOTES
File Name : manageVMSnapshots.ps1
Author : [Your Name]
[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[string]$OldNewDnsFile = "dns_old_new.csv",
[Parameter(Mandatory = $false)]
[string[]]$ComputerNames = @("localhost"),
[Parameter(Mandatory = $false)]
[string]$OutputFile = "updateIISBindingsResult.csv",
@davidlu1001
davidlu1001 / updateConfigWithCsv.ps1
Last active July 8, 2024 00:08
Update Config With CSV (includes old and new value)
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerNames = @($env:COMPUTERNAME),
[string[]]$ScanPaths = @("D:\", "E:\"),
[string]$OldNewDnsFile = "old_new_dns.csv",
[string]$OutputFile = "scanConfigResult_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv",
[string]$LogFile = "ScanLog_$(Get-Date -Format 'yyyyMMdd_HHmmss').log",
[int]$MaxConcurrentJobs = 5,
[int]$BatchSize = 1000,
@davidlu1001
davidlu1001 / scanConfig.ps1
Last active July 7, 2024 22:13
Scan Config
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerNames = @($env:COMPUTERNAME),
[string[]]$ScanPaths = @("D:\", "E:\"),
[string]$OutputFile = "DNSUrls_$(Get-Date -Format 'yyyyMMdd_HHmmss').csv",
[string]$LogFile = "ScanLog_$(Get-Date -Format 'yyyyMMdd_HHmmss').log",
[string]$UrlPattern = '(?i)([a-z0-9-]+\.)+co\.nz',
[int]$MaxConcurrentJobs = 5,
[int]$BatchSize = 1000
@davidlu1001
davidlu1001 / RemoteOps.Tests.ps1
Created July 4, 2024 07:07
Testing RemoteOps.ps1 with Pester
# RemoteOps.Tests.ps1
BeforeAll {
. $PSScriptRoot\RemoteOps.ps1
Mock Write-Log {}
Mock Resolve-FullPath { $Path }
Mock Get-Content { "Write-Output 'Test Script'" }
}
Describe "RemoteOps - Command Execution" {
@davidlu1001
davidlu1001 / setReg.ps1
Created July 2, 2024 03:50
Set REG values
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$regPath,
[Parameter(Mandatory=$true)]
[string]$regName,
[Parameter(Mandatory=$true)]
[string]$regNewValue,
@davidlu1001
davidlu1001 / getReg.ps1
Last active July 2, 2024 21:40
Get REG baed on Key or Value
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)]
[string]$regKeyPattern = '.*',
[Parameter(Mandatory=$false)]
[string]$regValuePattern = '.*',
[Parameter(Mandatory=$false)]
[string[]]$registryPaths = @("HKLM:\SOFTWARE\WOW6432Node\Google"),
[Parameter(Mandatory=$false)]
[string[]]$excludePaths = @("HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Google\Update*"),
@davidlu1001
davidlu1001 / ops.ps1
Last active July 22, 2024 23:19
Operation scripts for copy files and run commands on remote servers
<#
.SYNOPSIS
Executes commands or copies files on remote computers.
.DESCRIPTION
This script provides functionality to execute commands or copy files on multiple remote computers simultaneously.
It supports both running commands/scripts and copying files/directories.
.PARAMETER ComputerName
Specifies the target computers. Can be used with or without ConfigFile.