Instantly share code, notes, and snippets.

View Test-DynamicParamCreation.ps1
# Link to original question:
function Test-DynamicParamCreation {
Example of how to make dynamic param decisions based on other dynamic params.
NOTE: This probably isn't a good idea, as reflection is used to get at private
members of the PowerShell engine.
This function has a dynamic parameter named '-OtherDynamicParameterName' that
View DetectPreviousCommandArgCompleter.ps1
# See here for question:
function Test-DetectProperty {
Proof of concept to show that inspecting preceding command elements is possible
from within ArgumentCompleters, at least in a limited way.
Get-Service | Test-DetectProperty -Property <PressTab>
View ConditionalAceTest.cs
This is meant to be saved as a .cs file, and called with Add-Type inside PowerShell:
Add-Type -Path c:\path\to\this\gist.cs
using System;
using System.Security.Principal;
using System.Collections.Generic;
using System.Linq;
View QueryServiceObjectSecurity.ps1
NOTE: I think you have to run this as an admin b/c ServiceHandle seems to
be null when not elevated. Also, this can't be used to get the SACL
(ServiceHandle probably isn't opened with that access requested, and
this code doesn't do privilege modifications). If you really want to
get around these problems, you can probably use reflection to get at
the GetServiceHandle() private method on the ServiceController
instance. That might work as a non-elevated user...