Skip to content

Instantly share code, notes, and snippets.

@bielawb
Created June 25, 2022 22:34
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 bielawb/911118972b5963375fe8d8654cca8456 to your computer and use it in GitHub Desktop.
Save bielawb/911118972b5963375fe8d8654cca8456 to your computer and use it in GitHub Desktop.
Przeszukiwanie kodu za pomocą AST
using namespace System.Management.Automation.Language
$znajda = @((Get-ChildItem -Path *\*.ps1 | Convert-Path).ForEach{
(
[Parser]::ParseFile($_, [ref]$null, [ref]$null)
).Find(
{
$args[0] -is [CommandAst] -and
$args[0].CommandElements[0].Value -eq 'Stop'
},
$true
)
}).Extent[0]
$start = $znajda.StartLineNumber - 2
$end = $znajda.EndLineNumber + 2
(Get-Content -Path $znajda.File)[$start..$end]
# Na wyjściu...
$splat = @{
ErrorAction = Stop
Verbose = $true
}
Get-Process -Id $PID @splat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment