foreach ($pair in $pairs) { $filecontent = $filecontent -replace $pair.oldword,$pair.newword }
$pairs = Import-Csv csvfile.txt
$filecontent = Get-Content -Path file.txt
$filecontent | Foreach-Object {
foreach ($pair in $pairs) {
$_ -replace $pair.oldword, $pair.newword
}
} |
Set-Content -Path file.txt
Get-Process chrome | Stop-Process -Force
Start-ThreadJob
использует Powershell Runspace, которое, конечно, занимает время и память, хотя и поменьше, чем Start-Job, который фактически ещё один процесс Powershell порождает.Foreach-Object -Parallel
- это всё в рамках одного процесса, но многопоточно[System.Collections.ArrayList]$searchBytes += , $searchHexPattern
>$a = 1..10000
>[System.Collections.ArrayList]$searchBytes = New-Object System.Collections.ArrayList
>measure-command { foreach ($i in $a) { [System.Collections.ArrayList]$searchBytes += $i } }
Milliseconds : 681
TotalMilliseconds : 1681,7805
> [System.Collections.ArrayList]$searchBytes = New-Object System.Collections.ArrayList
> measure-command { foreach ($i in $a) { [void]$searchBytes.Add($i) } }
Milliseconds : 24
TotalMilliseconds : 24,8517
[pscustomobject]@{'search' = 'xxx'; 'replace'='yyy'}
....
command -search $data.search -replace $data.replace
$message = "Завершен процесс: $($process.Name) По причине
\\Server01\process(idle)\% processor time
$process = Get-Process someprocess
$process.PriorityClass = 'Idle'
function Convert-HexStringToByteArray {
param (
[string]$hexString
)
$hexString = $hexString -replace ' ', ''
if ($hexString.Length % 2 -ne 0) {
throw "Invalid hex string length."
}
$byteArray = New-Object System.Collections.ArrayList
for ($i = 0; $i -lt $hexString.Length; $i += 2) {
[void]$byteArray.Add([Convert]::ToByte($hexString.Substring($i, 2), 16))
}
[byte[]]$byteArray
}