MegaBites-AI/Windows-powershell
0372
1#requires -RunAsAdministrator2 3param(4 $ETLFileName = '.\PerfViewData.etl',5 6 [Parameter(Mandatory)]7 [scriptblock]8 $ScriptBlock,9 10 $LogFileName = '.\perfview.log',11 $PowerShellPath = $(Get-Command -Name pwsh.exe).Source,12 $PerfViewPath = $(Get-Command -Name PerfView.exe).Source13)14 15$EncodedScriptBlock = [System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($ScriptBlock.ToString()))16$perfViewArgs = @(17 '/AcceptEula'18 '/ThreadTime'19 "/LogFile=$LogFileName"20 "/DataFile:$ETLFileName"21 '/noRundown'22 '/Merge'23 '/Zip:False'24# GCSampledObjectAllocationHigh is sometimes useful, but quite expensive so not included by default25# '/ClrEvents=default+GCSampledObjectAllocationHigh'26 '/Providers:*Microsoft-PowerShell-Runspaces,*Microsoft-PowerShell-CommandDiscovery,*Microsoft-PowerShell-Parser,*Microsoft.Windows.PowerShell'27 'run'28 """$PowerShellPath"""29 '-NoProfile'30 '-EncodedCommand'31 $EncodedScriptBlock32)33 34$process = Start-Process -FilePath $PerfViewPath -ArgumentList $perfViewArgs -PassThru35$process.WaitForExit()36 37Get-Content $LogFileName | Out-Host38 