Skip to content

Instantly share code, notes, and snippets.

View SteveL-MSFT's full-sized avatar

Steve Lee SteveL-MSFT

View GitHub Profile
hello world
]633;Completions?
param(
[Parameter(ValueFromPipeline=$true)]
[ValueType]
$profileEvent
)
begin {
$profileEvents = [System.Collections.Generic.List[object]]::new()
}
param(
[Parameter(ValueFromPipeline)]
[string]$json
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100 -AsHashtable
$location = "/"
function Test-Location ($path) {
param(
[Parameter(ValueFromPipeline)]
[string]$json,
[Parameter(Mandatory,Position=0)]
[string]$find
)
$obj = ConvertFrom-Json -InputObject $json -Depth 100
@SteveL-MSFT
SteveL-MSFT / start-netprocess.ps1
Created December 10, 2018 18:51
Create Process with NetCredentials only
param($commandLine, [pscredential]$credential)
$csharp = @'
using System;
using System.Runtime.InteropServices;
public class Advapi32
{
[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Unicode)]
public static extern bool CreateProcessWithLogonW(
using System;
using System.Runtime.InteropServices;
namespace myps
{
public static class GetProcArgv
{
private const int CTL_KERN = 1;
private const int KERN_ARGMAX = 8;
private const int KERN_PROCARGS2 = 49;
@SteveL-MSFT
SteveL-MSFT / Update-Code.ps1
Last active September 2, 2021 02:41
Insert space after closing space in C# code
# Usage example for one commit per directory:
# dir -Recurse -Path . -Directory | % { $dir = $_; dir -path $dir.fullname *.cs | % { ~/test/update-code.ps1 -path $_.fullname; git add $_.fullname }; git commit -m "Update $($dir.name)" }
param($path)
$src = Get-Content $path -Raw
$skip = " get; set; "
# this matches a closing brace that is not followed by:
# catch, else, finally, another closing brace, newline, space, hash, slash (comment), * (comment)
@SteveL-MSFT
SteveL-MSFT / get-winrtversion.ps1
Created August 27, 2021 03:07
Example calling WnRT API from PS7 to get Windows version information
# adapted from https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/identifying-windows-version-part-2
# download and unzip latest https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref and get these dlls from the 'lib' folder
Add-Type -AssemblyName ./winrt.runtime.dll
Add-Type -AssemblyName .\Microsoft.Windows.SDK.NET.dll
# define call and information to query
[Collections.Generic.List[System.String]]$names = 'DeviceFamily',
'OSVersionFull',
'FlightRing',
@SteveL-MSFT
SteveL-MSFT / Get-Commands.ps1
Created March 16, 2021 15:06
Find modules/commands used by script
param($file)
$tokens = $null
$err = $null
$file = Resolve-Path $file
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$tokens, [ref]$err)
$commands = $ast.FindAll({$true},$true) | ? { $_ -is [System.Management.Automation.Language.CommandAst] } | % { $_.CommandElements[0].Value } | Sort-Object -Unique
$sources = [System.Collections.Generic.List[string]]::new()
$commands | % {
@SteveL-MSFT
SteveL-MSFT / render.ps1
Last active September 2, 2021 02:39
Example using System.Commandline.Rendering.dll
using namespace System.CommandLine.Rendering
add-type -AssemblyName ./System.CommandLine.Rendering.dll
$cs = [ContainerSpan]::new(
[StyleSpan]::UnderlinedOn(),
[ForegroundColorSpan]::Green(),
[BackgroundColorSpan]::Yellow(),
[ContentSpan]::new("hello"),
[StyleSpan]::UnderlinedOff()