Skip to content

Instantly share code, notes, and snippets.

Class AdhcResult {
[string]$Source
[string]$TestName
[bool]$Pass
$Was
$ShouldBe
[string]$Category
[string]$Message
$Data
[string[]]$Tags
@gerane
gerane / wmi_provider_association.ps1
Created October 11, 2017 04:42 — forked from mattifestation/wmi_provider_association.ps1
Enumerates WMI providers, the DLLs that back the provider, and the classes hosted by the provider.
<#
Author: Matthew Graeber (@mattifestation)
License: BSD 3-Clause
#>
function Get-WmiNamespace {
[OutputType([String])]
Param (
[String]
[ValidateNotNullOrEmpty()]
@gerane
gerane / Struct.ps1
Created May 8, 2017 10:57 — forked from proxb/Struct.ps1
Using PowerShell and Reflection to dynamically build a Struct with Constructors and Methods
#region Module Builder
$Domain = [AppDomain]::CurrentDomain
$DynAssembly = New-Object System.Reflection.AssemblyName(([guid]::NewGuid().ToString()))
$AssemblyBuilder = $Domain.DefineDynamicAssembly($DynAssembly, [System.Reflection.Emit.AssemblyBuilderAccess]::Run) # Only run in memory
$ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(([guid]::NewGuid().ToString()), $False)
#endregion Module Builder
#region STRUCTs
#Order of creating these Structs is important
#region MyStruct
$Attributes = 'AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, BeforeFieldInit'
@gerane
gerane / PSReadline_config.ps1
Created March 1, 2017 16:54 — forked from rkeithhill/PSReadLine_config.ps1
PSReadline configuration updated for PSReadline v1.1
# Need to explicitly import PSReadLine in a number of cases: Windows versions < 10 and
# x86 consoles that aren't loading PSReadLine.
# Source: https://gist.github.com/rkeithhill/3103994447fd307b68be#file-psreadline_config-ps1
# Other hosts (ISE, ConEmu) don't always work as well with PSReadline.
if ($host.Name -ne 'ConsoleHost') { return }
# PSReadline hasn't been auto-imported, try to manually import it
if (!(Get-Module PSReadline -ErrorAction SilentlyContinue)) {
if (!$IsLinux -and !$IsOSX -and ([IntPtr]::Size -eq 4) -and !(Get-Module -ListAvailable PSReadline)) {
@gerane
gerane / poco.psm1
Created December 21, 2016 04:41 — forked from yumura/poco.psm1
powershell peco
# Load
Split-Path $MyInvocation.MyCommand.Path -Parent | Push-Location
Get-ChildItem poco_*.ps1 | %{. $_}
Pop-Location
function Select-Poco
{
Param
(
[Object[]]$Property = $null,
@gerane
gerane / Faking_Static_Call_in_Pester.ps1
Created May 25, 2016 00:51 — forked from nohwnd/Faking_Static_Call_in_Pester.ps1
Faking call to external static method in Pester
add-type -TypeDefinition @"
using System;
public static class KeyboardEventTestUtil {
public static string keybd_event(byte bVk, byte bScan, UInt32 dwFlags, System.UIntPtr dwExtraInfo) {
return string.Format("{0}:{1}:{2}:{3}", bVk,bScan,dwFlags,dwExtraInfo);
}
}
"@
describe "t" {
@gerane
gerane / TestingStartService.ps1
Created May 25, 2016 00:50 — forked from nohwnd/TestingStartService.ps1
Testing start service
function EnsureServiceStarted {
param($Name)
Start-Service -name $name
$service = Get-Service -Name $name
$service.Status -eq [ServiceProcess.ServiceControllerStatus]::Running
}
Describe "Ensure service is started" {
It "Started service returns true" {
mock start-service {}
@gerane
gerane / nxlog.conf
Created February 25, 2016 00:46 — forked from chelming/nxlog.conf
NXLOG config that will parse SCCM and IIS logs
## Please set the ROOT to the folder your nxlog was installed into,
## otherwise it will not start.
#define ROOT C:\Program Files\nxlog
define ROOT C:\Program Files (x86)\nxlog
define CERTDIR %ROOT%\cert
Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
@gerane
gerane / RegRunner.cs
Created January 22, 2016 01:49
Executes Encrypted File From Registry
using System;
using System.IO;
using System.Text;
using Microsoft.Win32;
using System.IO.Compression;
using System.EnterpriseServices;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security.Cryptography;