Skip to content

Instantly share code, notes, and snippets.

View SteveL-MSFT's full-sized avatar

Steve Lee SteveL-MSFT

View GitHub Profile
function Get-SuspiciousElement {
param ( [scriptblock]$sb, [switch]$InPlace )
$susProp = $sb.ast.gettype().GetProperty("HasSuspiciousContent", [reflection.bindingflags]"NonPublic,Instance")
$suspiciousContent = ""
$sb.Ast.FindAll({$true}, $true) | %{
      if ( $susProp.GetValue($_) ) {
            $suspiciousContent = $_.Extent.Text
      }
$ExecutionContext.InvokeCommand.CommandNotFoundAction =
{
param(
[string]
$commandName,
[System.Management.Automation.CommandLookupEventArgs]
$eventArgs
)
@SteveL-MSFT
SteveL-MSFT / profile.ps1
Last active March 11, 2024 01:21
PowerShell Prompt
#Requires -Version 7
# Version 1.2.13
# check if newer version
$gistUrl = "https://api.github.com/gists/a208d2bd924691bae7ec7904cab0bd8e"
$latestVersionFile = [System.IO.Path]::Combine("$HOME",'.latest_profile_version')
$versionRegEx = "# Version (?<version>\d+\.\d+\.\d+)"
if ([System.IO.File]::Exists($latestVersionFile)) {
@SteveL-MSFT
SteveL-MSFT / graphql.ps1
Last active October 29, 2023 03:11
GraphQL Query Example
$query = @"
query {
organization(login: "powershell") {
name
url
repository(name: "powershell") {
name
pullRequests(last: 20, states: [OPEN]) {
edges {
node {
param(
[string]$include = "*.resx"
)
$filesToExclude = @(
'FlashExtractStrings.resx'
'*Xaml*.resx'
'TabCompletionStrings.resx'
'*UICultureResources.resx'
'ComputerResources.resx'
write-progress -id 1 -Activity "Getting all modules"
$modules = find-module -Repository PSGallery
$moduleNames = $modules.Name
$fz = [System.Reflection.Assembly]::GetAssembly([System.Management.Automation.PowerShell]).GetType("System.Management.Automation.FuzzyMatcher")
$fzmatch = $fz.GetMethod("GetDamerauLevenshteinDistance")
$fzmatches = @{}
$i = 1
foreach ($module in $moduleNames) {
write-progress -id 1 -Activity "Searching" -Status "$module" -PercentComplete ([int32]([double]$i / [double]($moduleNames.Count) * 100))
@SteveL-MSFT
SteveL-MSFT / base64.ps1
Last active October 14, 2022 14:28
PowerShell Base64 Encode/Decode test
# Base64 algorithm borrowed from https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64
function ConvertTo-Base64String ($string)
{
$base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
$result = [System.Text.StringBuilder]::new()
$pad = ""
$count = $string.Length % 3;
# string needs to be multiple of 3 characters
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,Position=0)]
[string]$command,
[Parameter(Position=1)]
[string]$class
)
if ($command -eq 'path') {
using System;
using System.Management.Automation;
using System.Text;
namespace ClipboardReverse
{
[Cmdlet(VerbsCommon.Get,"ClipboardReverse")]
[OutputType(typeof(string))]
public class ClipboardReverse : PSCmdlet
{
]