感谢大侠支招, 匹配还是有点问题, 结果如下:
Get-Content
---------- Example 1: Get the content of a text file ----------
1..100 | ForEach-Object { Add-Content -Path .\LineNumbers.txt -Value "This is line $_." }
Get-Content -Path .\LineNumbers.txt
ate the `LineNumbers.txt` file. The variable `$_` represents the array values as each object is sent down the pipeline. The `Get-Content` cmdlet uses the P
--- Example 2: Limit the number of lines Get-Content returns ---
Get-Content -Path .\LineNumbers.txt -TotalCount 5
-- Example 3: Get a specific line of content from a text file --
(Get-Content -Path .\LineNumbers.txt -TotalCount 25)[-1]
The `Get-Content` command is wrapped in parentheses so that the command completes before going to the next step. `Get-Content`returns an array of lines, th
--------- Example 4: Get the last line of a text file ---------
Get-Item -Path .\LineNumbers.txt | Get-Content -Tail 1
This example uses the `Get-Item` cmdlet to demonstrate that you can pipe files into the `Get-Content` parameter. The Tail parameter gets the last line of t
---- Example 5: Get the content of an alternate data stream ----
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Test\Stream.txt:DATA
PSChildName : Stream.txt::$DATA
Stream : :$DATA
# Retrieve the content of the primary, or $DATA stream.
Get-Content -Path .\Stream.txt -Stream $DATA
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\Test\Stream.txt::$DATA
PSChildName : Stream.txt::$DATA
Stream : :$DATA
Get-Content -Path .\Stream.txt -Stream NewStream
). By default `Get-Content` only retrieves data from the primary, or `$DATA` stream. Streams can be used to store hidden data such as attributes, security
------------------ Example 6: Get raw content ------------------
$raw = Get-Content -Path .\LineNumbers.txt -Raw
$lines = Get-Content -Path .\LineNumbers.txt
Write-Host "Raw contains $($raw.Count) lines."
Write-Host "Lines contains $($lines.Count) lines."
----------- Example 7: Use Filters with Get-Content -----------
Get-Content -Path C:\Temp\* -Filter *.log
--------- Example 8: Get file contents as a byte array ---------
$byteArray = Get-Content -Path C:\temp\test.txt -Encoding Byte -Raw
Get-Member -InputObject $bytearray