Skip to content

Instantly share code, notes, and snippets.

@SteveL-MSFT
Created April 20, 2024 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveL-MSFT/a9d0413137ca9e8ae7d0ff6a18e0624d to your computer and use it in GitHub Desktop.
Save SteveL-MSFT/a9d0413137ca9e8ae7d0ff6a18e0624d to your computer and use it in GitHub Desktop.
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