Skip to content

Instantly share code, notes, and snippets.

View davidlu1001's full-sized avatar

David Lu davidlu1001

View GitHub Profile
@davidlu1001
davidlu1001 / terraform_include_exclude
Last active November 24, 2021 16:35
Makefile for Terraform to support include/exclude
PLAN_OPTIONS ?=
APPLY_OPTIONS ?=
EXCLUDE ?=
INCLUDE ?=
# For Terraform 0.12 (using `-no-color` to avoid dealing with terminal color)
define PLAN_OPTIONS_EXCLUDE
$(shell terraform show -no-color current.plan | perl -nle 'if (/\s# (.*?)\s/) {print $$1}' | grep -E -v '$(1)' | sed -e 's/^/-target="/g' -e 's/$$/"/g' | xargs)
endef
@davidlu1001
davidlu1001 / fix_vscode_copilot_cert.sh
Created March 13, 2022 22:54
Fix Github Copilot cert issue behind proxy for VSCode
#!/usr/bin/env bash
set -uo pipefail
_VSCODEDIR="$HOME/.vscode/extensions"
_COPILOTDIR=$(ls "${_VSCODEDIR}" | grep -E "github.copilot-[1-9].*" | sort -V | tail -n1) # For copilot
_COPILOTDEVDIR=$(ls "${_VSCODEDIR}" | grep "github.copilot-nightly-" | sort -V | tail -n1) # For copilot-nightly
_EXTENSIONFILEPATH="${_VSCODEDIR}/${_COPILOTDIR}/dist/extension.js"
_DEVEXTENSIONFILEPATH="${_VSCODEDIR}/${_COPILOTDEVDIR}/dist/extension.js"
@davidlu1001
davidlu1001 / Get-SSLCertificateExpiryDateFromURL.ps1
Last active January 7, 2024 22:47
Get SSL Certificate Expiry Date From URL
function Get-SSLCertificateExpiryDetailsFromURL {
param (
[ValidateNotNullOrEmpty()]
[string]$InputFilePath = ".\input.csv",
[string]$OutputFilePath = ".\output.csv",
[bool]$ExportToCsv = $true, # Control CSV export
[int]$TimeoutMilliseconds = 20000, # Timeout duration in milliseconds
@davidlu1001
davidlu1001 / Join-CustomObject.ps1
Last active January 11, 2024 05:21
Join Custom Object
function Join-CustomObject {
param (
[Parameter(Mandatory = $true)]
[pscustomobject[]]$FirstObject,
[Parameter(Mandatory = $true)]
[pscustomobject[]]$SecondObject,
[Parameter(Mandatory = $true)]
[string]$FirstObjectJoinProperty,
@davidlu1001
davidlu1001 / getEventLogSource.ps1
Last active January 31, 2024 03:25
Get WinEventLog Source / ProviderName
# List of remote servers
$servers = @("Server1", "Server2", "Server3") # Replace with your server names
# List of Event Log names to query
$logNames = @("System", "Application", "Security") # Replace with your desired log names
# File paths for output
$detailedOutputFile = "EventLogSources.csv"
$uniqueOutputFile = "UniqueEventLogSources.csv"
@davidlu1001
davidlu1001 / getEventLogSourceWithMessage.ps1
Last active February 1, 2024 02:49
Get EventLog Source with latest message for each LogLevelType
function Get-EventLogData {
param(
[string[]]$logNames,
[datetime]$startDate,
[string]$server
)
$results = @()
foreach ($logName in $logNames) {
try {
Write-Host "Querying LogName: $logName on $server"
@davidlu1001
davidlu1001 / getEventLogMessageForInputSource.ps1
Last active February 11, 2024 21:28
Get EventLogMessage For Input Source
function Get-EventLogData {
param(
[Parameter(Mandatory = $true)]
[string[]]$Servers,
[Parameter(Mandatory = $true)]
[string[]]$LogNames,
[Parameter(Mandatory = $true)]
[string[]]$ProviderNames,
@davidlu1001
davidlu1001 / win_upgrade_plan.md
Created February 9, 2024 03:28
Windows upgrade plan

Windows Server Upgrade and Migration Plan: 2012 to 2019

Objective

This document outlines a detailed plan for upgrading and migrating from Windows Server 2012 to Windows Server 2019. It covers pre-migration assessment, setup on the new server, application and data migration, testing, and post-migration tasks.


1. Pre-Migration Assessment

@davidlu1001
davidlu1001 / getDotNetVersionInfo.ps1
Last active February 16, 2024 23:47
Get .NET version info
param(
[switch]$ExportToCsv
)
# Attempt to execute 'dotnet --info' and capture the output
try {
$dotnetInfo = & dotnet --info 2> $null | Out-String
} catch {
$dotnetInfo = $null
}
@davidlu1001
davidlu1001 / Get-TcpConnectionsInfo.ps1
Created March 4, 2024 09:43
Get Tcp Connections Info
param(
[switch]$ExportToCsv,
[string]$CsvPath = "C:\ports_info.csv"
)
function Get-TcpConnections {
try {
$connections = Get-NetTCPConnection
$processes = Get-Process