-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathGet-DIBBlock.ps1
35 lines (30 loc) · 873 Bytes
/
Get-DIBBlock.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
function Get-DIBBlock {
param(
[Parameter(Mandatory)]
$fileName
)
$content = Get-Content $fileName
$lineNumber = -1
$locations = foreach ($line in $content) {
$lineNumber++
if ($line.Startswith('#!')) {
$lineNumber
}
}
for ($idx = 0; $idx -lt $locations.Count; $idx++) {
$startBlock = $locations[$idx] + 1
if ($idx + 1 -eq $locations.Count) {
$endBlock = $content.Count - 1
}
else {
$endBlock = $locations[$idx + 1] - 1
}
[pscustomobject][ordered]@{
FileName = $fileName
Block = $idx
Range = '{0}..{1}' -f $startBlock, $endBlock
Type = $content[$locations[$idx]]
Content = $content[$startBlock..$endBlock] -join "`n"
}
}
}