Skip to content

Instantly share code, notes, and snippets.

@changbowen
changbowen / CycleWallpaperWithDate.ps1
Last active November 17, 2023 14:22
PowerShell script to be used with bginfo.exe that cycles wallpaper based on date
param(
# The folder containing the images
[Parameter()][string]$imgPath = $env:imgPath,
[Parameter()][string]$bgiPath = $env:bgiPath
)
if ([string]::IsNullOrEmpty($imgPath) -or [string]::IsNullOrEmpty($bgiPath)) {
throw "You need to set imgPath and bgiPath environment variables or pass them in."
}
#region function definitions
@changbowen
changbowen / remove_dameware.ps1
Created August 20, 2019 03:46
remove devices leftover from a dameware uninstall
################################
# Script created by Carl Chang #
################################
$devcon = 'path\to\devcon_x64.exe'
# uninstall dameware products
wmic product where "name like '%%dameware%%'" call uninstall
# remove left-over devices
@changbowen
changbowen / auto_default_gateway_metric.ps1
Last active November 7, 2024 01:38
PowerShell script that monitors for IP changes and updates route metric according to internet reachability
function ipChangeHandler {
Write-Host "Detected an IP change..."
Write-Host "Collecting connections information..."
$connObjs = New-Object System.Collections.ArrayList
$ints = Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp -AddressState Preferred
foreach ($int in $ints) {
$_alias = $int.InterfaceAlias
$_index = $int.InterfaceIndex
$_ipaddr = $int.IPAddress
$intCfg = $int | Get-NetIPConfiguration
@changbowen
changbowen / yaml.json
Last active September 11, 2019 07:42
VS Code Ansible snippets
{
"Insert new variable": {
"prefix": ": ",
"body": [
": \"{{ ${2:value} }}\"$0"
],
"description": "Insert new ansible variable"
},
"Insert conditional list": {
"prefix": "cond",
@changbowen
changbowen / Test-RPC.ps1
Created October 11, 2019 09:05
modified version of the Test-RPC from Ryan Ries
# Author: Ryan Ries [MSFT]
# Origianl date: 15 Feb. 2014
#Requires -Version 3
Function Test-RPC {
[CmdletBinding(SupportsShouldProcess = $True)]
Param(
[Parameter(ValueFromPipeline = $True)][String[]]$ComputerName = 'localhost',
[int[]]$Ports = $null
)
BEGIN {
function natualSort {
PARAM(
[System.Collections.ArrayList]$Array,
[switch]$Descending
)
Add-Type -TypeDefinition @'
using System;
using System.Collections;
using System.Collections.Generic;
let nsxServer = location.host;
let xsrfToken = await fetch(`https://${nsxServer}/api/v1/reverse-proxy/usersessionInfo`).then(r => r.text()).then(r => JSON.parse(r).xsrfToken);
let pageSize = 500;
// NSX groups with effective VM members
fetch(`https://${nsxServer}/policy/api/v1/search/aggregate?page_size=${pageSize}&cursor=0&sort_by=display_name&sort_ascending=true`, {
"headers": {
"accept": "application/json, text/plain, */*",
"accept-language": "en-US",
"content-type": "application/json;charset=UTF-8",
@changbowen
changbowen / cheatsheet.sh
Created December 25, 2020 06:04
Linux Cheatsheet
# Top 20 largest folders under /var (including /var)
sudo du -h /var | sort -rh | head -20
@changbowen
changbowen / Get-DellWarranty.ps1
Last active September 2, 2021 08:15
Dell API - Get Warranty Info from Service Tag
Function Get-DellWarranty {
Param(
[Parameter(Mandatory,ValueFromPipeline)]
[String[]] $ServiceTag,
[Parameter(Mandatory)]
[string] $APIKey,
[Parameter(Mandatory)]
[string] $APISecret,