Skip to content

Instantly share code, notes, and snippets.

@lzybkr
lzybkr / Convert-ArgumentCompleterRegistrationScript.ps1
Created April 27, 2015 18:41
Script to convert TabExpansion++ completers to use Register-ArgmentCompleter
param(
[Parameter(ValueFromPipelineByPropertyName = $true, Mandatory, Position = 0)]
[Alias("PSPath")]
[string]$Path,
[string]$OutputPath
)
process
<Configuration>
<ViewDefinitions>
<View>
<Name>Measure-Object-Output</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.GenericMeasureInfo</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<Configuration>
<ViewDefinitions>
<View>
<Name>MatchInfo</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.MatchInfo</TypeName>
</ViewSelectedBy>
<CustomControl>
<CustomEntries>
<CustomEntry>
@lzybkr
lzybkr / AnalyzeCurlUsage.ps1
Created August 21, 2016 00:43
Analyze curl in PowerShell scripts
using namespace System.Management.Automation.Language
function AnalyzeCurlUsage
{
param([Parameter(ValueFromPipeline)][Alias('PSPath')][string]$path)
process {
$err = $null
$tokens = $null
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class NativeConsoleMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr GetStdHandle(int handleId);
[CmdletBinding(DefaultParameterSetName = 'FixedG')]
param(
[Parameter(ParameterSetName = 'FixedR', Mandatory)]
[ValidateRange(0, 255)]
$fixedR,
[Parameter(ParameterSetName = 'FixedG')]
[ValidateRange(0, 255)]
[int]$fixedG = 105,
enum Color { Red; Green; Blue }
[System.Diagnostics.Tracing.EventSource(Name = "MyPSEventSource")]
class C : System.Diagnostics.Tracing.EventSource
{
[System.Diagnostics.Tracing.Event(1)]
[void] SomeRandomEvent([string]$Message, [Color]$Color)
{
$this.WriteEvent([int]1, [string]$Message, [int]$Color)
using namespace System.Text.RegularExpressions
param([string[]]$extensions = 'ps1')
function Get-FileEncoding
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)] [string]$Path
)
@lzybkr
lzybkr / FormatHex.cs
Created March 15, 2017 22:11
Formatting hex objects
using System;
using System.Runtime.InteropServices;
using System.Reflection;
namespace App
{
enum E1 : byte
{
e1 = 5
}
@lzybkr
lzybkr / Invoke-PerfviewPS.ps1
Created October 17, 2017 00:19
Run PowerShell via perfview with PowerShell EventSource sources
param(
$etlFile = '.\perfviewdata.etl',
$scenario = 'echo 1',
$logFile = '.\perfview.log')
$perfViewArgs = @(
'/AcceptEula'
'/ThreadTime'
"/LogFile=$logFile"
"/DataFile:$etlFile"