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
@proxb
proxb / Struct.ps1
Created April 27, 2017 22:54
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'
@mattifestation
mattifestation / wmi_provider_association.ps1
Last active August 16, 2022 05:14
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()]
@rkeithhill
rkeithhill / VSCode-keybindings.json
Last active April 30, 2020 18:43
My Visual Studio Code customized keyboard shorcuts
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "alt+n", "command": "explorer.newFile" },
{ "key": "alt+shift+s", "command": "PowerShell.InvokeRegisteredEditorCommand",
"args": { "commandName": "ConvertToSplatExpression" },
"when": "editorLangId == 'powershell'" },
{ "key": "ctrl+shift+q", "command": "workbench.action.toggleMaximizedPanel" },
{ "key": "ctrl+shift+s", "command": "workbench.action.files.saveAll" },
{ "key": "ctrl+shift+t", "command": "workbench.action.tasks.test" },
{ "key": "ctrl+alt+t", "command": "workbench.action.tasks.runTask" },
@nohwnd
nohwnd / TestingStartService.ps1
Last active May 25, 2016 00:50
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 {}
@nohwnd
nohwnd / Faking_Static_Call_in_Pester.ps1
Created May 20, 2016 13:25
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" {
@yumura
yumura / poco.psm1
Last active April 6, 2023 18:58
powershell peco
# Load
Split-Path $MyInvocation.MyCommand.Path -Parent | Push-Location
Get-ChildItem poco_*.ps1 | %{. $_}
Pop-Location
function Select-Poco
{
Param
(
[Object[]]$Property = $null,
@rkeithhill
rkeithhill / PSReadLine_config.ps1
Last active December 10, 2023 03:03
Config file for PSReadLine
# Other hosts (ISE, ConEmu) don't always work as well with PSReadLine.
# Also, if PS is run with -Command, PSRL loading is suppressed.
$psrlMod = Get-Module PSReadLine
if (($null -eq $psrlMod) -or ($host.Name -eq 'Windows PowerShell ISE Host')) {
return
}
elseif ($psrlMod.Version.Major -lt 2) {
throw "PSReadLine 1.x installed or not imported, import PSRL or ugprade to at least 2.x."
}
@HarmJ0y
HarmJ0y / gist:fd98c4f16575ba28c091
Last active April 27, 2023 13:56
Powershell ADSI tricks
# Add a domain user to a remote server local group, if your current user has admin over the remote machine
powershell -c ([ADSI]'WinNT://SERVER/Administrators,group').add('WinNT://DOMAIN/USER,user')
# Get all local groups on a remote server
powershell -c "([ADSI]'WinNT://SERVER,computer').psbase.children | where { $_.psbase.schemaClassName -eq 'group' } | foreach { ($_.name)[0]}"
# Find members of the local Administrators group on a remote server
powershell -c "$([ADSI]'WinNT://SERVER/Administrators,group').psbase.Invoke('Members') | foreach { $_.GetType().InvokeMember('ADspath', 'GetProperty', $null, $_, $null).Replace('WinNT://', '') }"
# Enable the local Administrator account on a remote server
@chelming
chelming / nxlog.conf
Last active December 9, 2020 15:35
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