Skip to content

Instantly share code, notes, and snippets.

@xcud
xcud / Get-Assemblies.ps1
Last active February 8, 2024 11:37
Gets a list of the assemblies loaded into memory in the current AppDomain.
<#
.Synopsis
Gets a list of the assemblies loaded into memory in the current AppDomain.
.Example
PS> Get-Assemblies power -NameOnly
Name
----
Microsoft.PowerShell.ConsoleHost.dll
Microsoft.PowerShell.Security.dll
@xcud
xcud / Load-Assembly.ps1
Created January 31, 2013 15:30
Pipeable shortcut for [reflection.assembly]::LoadFrom
<#
.Synopsis
Pipeable shortcut for [reflection.assembly]::LoadFrom.
.Example
PS> dir c:\foo.dll | Load-Assembly
GAC Version Location
--- ------- --------
False v2.0.50727 C:\foo.dll
@xcud
xcud / Get-NetworkStatistics.ps1
Last active December 12, 2015 03:49
Powershellized netstat
<#
.Synopsis
PowerShellized netstat. Building on Shay Levy's work
Shay Levy's Blog => http://blogs.microsoft.co.il/blogs/scriptfanatic/
.Example
PS> Get-NetworkStatistics skype | ft -AutoSize
Protocol LocalAddress LocalPort RemoteAddress RemotePort State ProcessName PID
-------- ------------ --------- ------------- ---------- ----- ----------- ---
@xcud
xcud / ParsedArgs.cs
Last active December 12, 2015 04:28
Simple string[] args => Dictionary<string, object> parser
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Xcud
{
/// <summary>
/// Simple command line argument parser.
@xcud
xcud / SimpleGAC.cs
Created February 5, 2013 12:58
A simple wrapper for GAC.cs from Microsoft KB Article KB317540
// System.GAC (a .Net wrapper for Fusion) implementation was too messy. Simplified here.
//
// Note, installing an assembly with the REFRESH flag specified does NOT work as advertised.
// Overwriting old GAC'd assemblies must be done manually as implemented below.
//
using System.Reflection;
using System.Text;
namespace Xcud.System.GAC
@xcud
xcud / Out-PDF.ps1
Created February 7, 2013 21:41
Writes a string to a PDF via Microsoft Word automation
<#
.Synopsis
Writes a string to a PDF via Microsoft Word automation
.Example
PS> ps | out-string | out-pdf -Path ".\processes.pdf"
#>
function Out-PDF() {
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$true)] $Text,
@xcud
xcud / Get-Content.ps1
Created February 14, 2013 19:15
Extend Get-Content to include a -Fast parameter; much less flexible but much more performant
<#
.Synopsis
Extend Get-Content to include a -Fast parameter; much less flexible but more performant
.Example
PS> (Measure-Command { Get-Content .\data.xml} ).TotalMilliseconds
1609.3267
PS> (Measure-Command { Get-Content .\data.xml -Fast} ).TotalMilliseconds
39.2511
#>
@xcud
xcud / Implement-Verbose.ps1
Last active December 13, 2015 19:18
Demonstrate built-in Verbose support
<#
.Synopsis
Demonstrate built-in Verbose support
.Example
PS> Correct-Example -Verbose
VERBOSE: This works
PS> Incorrect-Example -Verbose
PS> Incorrect-Example2 -Verbose
@xcud
xcud / DynamicWebServiceProxy.cs
Created February 22, 2013 16:10
I'm spoiled by PowerShell's New-WebServiceProxy. I want to poke around at a WCF but I don't want to precompile a WSDL, or add a service reference, or include a contract interface that'll break on compile when it changes. Let me just interact with the web services reflectively like I do in PowerShell. The performance profile is terrible. It does …
using System;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
namespace Xcud.Net
{
/// <example>
/// DynamicWebServiceProxy proxy = new DynamicWebServiceProxy(uri);
@xcud
xcud / AttributeOptionSet.cs
Created April 16, 2013 20:59
Extends Mono.Options, a better command line parser.
using System;
using System.Linq;
using Mono.Options;
namespace xcud
{
public class AttributedOptionSet : OptionSet
{
public static T Parse<T>(string[] args) where T : AttributedOptionSet, new()
{