View Test-DynamicParamCreation.ps1
# Link to original question: https://powershell.org/forums/topic/retrieve-the-input-value-of-the-dynamic-parameter/ | |
function Test-DynamicParamCreation { | |
<# | |
.SYNOPSIS | |
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. | |
.DESCRIPTION | |
This function has a dynamic parameter named '-OtherDynamicParameterName' that |
View DetectPreviousCommandArgCompleter.ps1
# See here for question: https://rohnspowershellblog.wordpress.com/2017/01/17/completing-parameter-values-with-other-parameter-values/#comment-437 | |
function Test-DetectProperty { | |
<# | |
.SYNOPSIS | |
Proof of concept to show that inspecting preceding command elements is possible | |
from within ArgumentCompleters, at least in a limited way. | |
.EXAMPLE | |
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... | |
#> |