Skip to content

Instantly share code, notes, and snippets.

@breezhang
breezhang / Invoke-Template.txt
Last active April 14, 2023 19:14
Embedding PowerShell in your C# Application author :Douglas Finke
function Invoke-Template {
param(
[string]$Path,
[Scriptblock]$ScriptBlock
)
function Get-Template {
param($TemplateFileName)
$content = [IO.File]::ReadAllText(
(Join-Path $Path $TemplateFileName) )
Invoke-Expression "@`"`r`n$content`r`n`"@"
---------------------------------------------------
Control Panel
module: CONTROL.EXE
command: rundll32.exe shell32.dll,Control_RunDLL
result: displays all the Control Panel icons in
an Explorer view
@breezhang
breezhang / Sample codeDOM API
Created August 21, 2012 11:52
Using CodeDOM to generate CSharp (C#) and VB code
//Copy from thottams@microsoft.com 15 Aug 2006 8:29 PM
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System.IO;
namespace ConsoleApplication1
{
@breezhang
breezhang / readme.txt
Created December 16, 2013 10:14
windump help
tcpdump advanced filters
========================
Sebastien Wains <sebastien -the at sign- wains -dot- be>
http://www.wains.be
$Id: tcpdump_advanced_filters.txt 36 2013-06-16 13:05:04Z sw $
Notes :
@breezhang
breezhang / openserialport.ps1
Created January 8, 2013 06:43
powershell setup serial com port or bluetooth modem
#make sure modem stuff
#(hardware flow control set up easy seme as cmd console write-line read-line ...) example bluetooth modem
#if just serial port(USB-RS232)you may be set rts enable
#serial port very slow io you know you need infinite patience
$port = new-Object System.IO.Ports.SerialPort COM7,115200,None,8,one
$port.RtsEnable =$true
start-Sleep -m 1000
$port.Open()
# device init need some time
#program enter sleep that make sure init task complete
@breezhang
breezhang / show simple .... .txt
Last active August 7, 2022 13:06
ansi detail ...
ANSI Escape Sequences
Wherever you see '#', that should be replaced by the appropriate number.
ESC code sequence Function
------------------- ---------------------------
Cursor Controls:
ESC[#;#H or ESC[#;#f Moves cusor to line #, column #
ESC[#A Moves cursor up # lines
ESC[#B Moves cursor down # lines
@breezhang
breezhang / demo.ps1
Last active August 3, 2022 20:20
Powershell Generic Collections powershell v3
New-Object System.Collections.ObjectModel.Collection["string"]
# from msdn
#[SerializableAttribute]
#[ComVisibleAttribute(false)]
#public class Collection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
#
@breezhang
breezhang / logon.ps1
Created February 20, 2012 07:12
Last Logon Times (Vista .. win7)
#source="http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/19/use-powershell-to-find-last-logon-times-for-virtual-#workstations.aspx?utm_source=twitterfeed&utm_medium=twitter"
$Computer = 'NJLT-Service'
$Win32OS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer
$Build = $Win32OS.BuildNumber
#The “If ($Build -ge 6001)” is the first decision point.
#if the build number is 6001 and above, the script block will run.
if ($Build -ge 6001)
{
$Win32User = Get-WmiObject -Class Win32_UserProfile -ComputerName $Computer
# updated for pseventing 1.1
if ((get-pssnapin pseventing -ea silentlycontinue) -eq $null) {
add-pssnapin pseventing
}
function add-eventhandler ($variable,
$eventName ,
[scriptblock]$script = $(throw "script cannot be null")) {
@breezhang
breezhang / x.bat
Created February 22, 2012 10:35
if y get error Get-ExecutionPolicy : Invalid class try this script :)
from http://msmvps.com/blogs/lduncan/pages/20217.aspx
How Do I Rebuilt a Corrupt WMI Repository?
The following can be done through a batch file or executed manually from the command line:
net stop winmgmt
c:
cd %systemroot%\system32\wbem
rd /S /Q repository