Created
April 20, 2024 04:45
-
-
Save SteveL-MSFT/a9d0413137ca9e8ae7d0ff6a18e0624d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
if ($suspiciousContent -ne "") { | |
if ($InPlace) { | |
$sb.Ast.Extent.Text.Replace($suspiciousContent, ">>> $suspiciousContent <<<") | |
} | |
else | |
{ | |
$suspiciousContent | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment