Skip to content

Instantly share code, notes, and snippets.

Carl Chang changbowen

  • United States
Block or report user

Report or block changbowen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@changbowen
changbowen / Test-RPC.ps1
Created Oct 11, 2019
modified version of the Test-RPC from Ryan Ries
View Test-RPC.ps1
# 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 {
@changbowen
changbowen / yaml.json
Last active Sep 11, 2019
VS Code Ansible snippets
View yaml.json
{
"Insert new variable": {
"prefix": ": ",
"body": [
": \"{{ ${2:value} }}\"$0"
],
"description": "Insert new ansible variable"
},
"Insert conditional list": {
"prefix": "cond",
@changbowen
changbowen / auto_default_gateway_metric.ps1
Last active Sep 20, 2019
PowerShell script that monitors for IP changes and updates route metric according to internet reachability
View auto_default_gateway_metric.ps1
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 / remove_dameware.ps1
Created Aug 20, 2019
remove devices leftover from a dameware uninstall
View remove_dameware.ps1
################################
# 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 / CycleWallpaperWithDate.ps1
Last active Aug 9, 2019
PowerShell script to be used with bginfo.exe that cycles wallpaper based on date
View CycleWallpaperWithDate.ps1
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 / Python.xml
Last active Aug 5, 2019
Python live templates for PyCharm
View Python.xml
<templateSet group="Python">
<template name="for" value="for $VAR$ in $ITERABLE$:&#10; $END$" description="Iterate (for ... in ...)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="&quot;iterable&quot;" alwaysStopAt="true" />
<variable name="VAR" expression="collectionElementName(ITERABLE)" defaultValue="&quot;item&quot;" alwaysStopAt="true" />
<context>
<option name="Python" value="true" />
</context>
</template>
<template name="fori" value="for $INDEX$, $VAR$ in enumerate($ITERABLE$):&#10; $END$" description="Iterate (for ... in enumerate)" toReformat="false" toShortenFQNames="true">
<variable name="ITERABLE" expression="pyIterableVariable()" defaultValue="" alwaysStopAt="true" />
@changbowen
changbowen / DpiImage.cs
Last active Sep 18, 2019
WPF Image control that does not scale with system DPI
View DpiImage.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace ZipImageViewer
{
public class DpiImage : Image
{
@changbowen
changbowen / get_cdp.py
Last active Aug 16, 2019
Getting CDP (Cisco Discovery Protocol) information via Python on specified list of ESXi hosts
View get_cdp.py
#!/usr/bin/env python
import sys
import atexit
from pyVim.connect import SmartConnectNoSSL, Disconnect
import pyVmomi
from pyVmomi import vim
from typing import List, Dict, Union
from tabulate import tabulate
from getpass import getpass
View NativeMethods.cs
public static class NativeMethods
{
[DllImport("user32.dll")]
private static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData);
private delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref Rect2 lprcMonitor, IntPtr dwData);
[DllImport("user32.dll")]
private static extern bool GetMonitorInfo(IntPtr hwnd, ref MonitorInfo mInfo);
[DllImport("Shcore")]
@changbowen
changbowen / Get-CDP.ps1
Last active Aug 14, 2019
Getting CDP (Cisco Discovery Protocol) information via PowerShell on specified list of ESXi hosts
View Get-CDP.ps1
<#
.SYNOPSIS
Get CDP information from one or more ESX hosts.
.PARAMETER VMHost
VMHost can be a list of the below entries:
- FQDN name of the host
- VMware.Vim.HostSystem (return type of 'Get-View -ViewType HostSystem')
- VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl (return type of 'Get-VMHost')
You can’t perform that action at this time.