-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbegin-end blocks.ps1
47 lines (39 loc) · 952 Bytes
/
begin-end blocks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Set-Content -Path .\testfile.txt -Value (1..1000)
break
function Update-File {
[CmdletBinding()]
param (
[string]$Path,
[parameter(ValueFromPipeline)]
[string]$Value
)
begin {
}
process {
[string[]]$Content = Get-Content -Path $Path
$Content = $Content.Replace($Value,'foo')
Set-Content -Path $Path -Value $Content
}
end {
}
}
Measure-Command -Expression {1..1000 | Update-File -Path .\testfile.txt}
break
function Update-File2 {
[CmdletBinding()]
param (
[string]$Path,
[parameter(ValueFromPipeline)]
[string]$Value
)
begin {
[string[]]$Content = Get-Content -Path $Path
}
process {
$Content = $Content.Replace($Value,'foo')
}
end {
Set-Content -Path $Path -Value $Content
}
}
Measure-Command -Expression {1..1000 | Update-File2 -Path .\testfile.txt}