Suitable for PowerShell3.0 or higher version
Sometimes, you may occasionally find the following code:
Copy Code code as follows:
$FilePath = "$env: Systemroot\windowsupdate.log"
$ContentsWithLinebreaks = (get-content $FilePath)-join "' R ' N"
Guess what it's like, get-content. The default text file is read as a single line, and a multiline array is returned, and the-join operator converts them to a separate string. And with PowerShell3.0 's low-key advent, there is such a parameter:-raw, it can be very efficient to get the same result of the above code:
Copy Code code as follows:
$FilePath = "$env: Systemroot\windowsupdate.log"
$ContentsWithLinebreaks = (get-content $FilePath)-join "' R ' N"
$ContentsWithLinebreaks 2 = get-content $FilePath-raw
$ContentsWithLinebreaks-eq $ContentsWithLinebreaks 2
Try to run the above code, $ContentWithLinebreaks and $contentwithlinebreaks2 may compare the results slightly different, the difference may be just the line break.
Then we continue to distinguish between false and true:
Copy Code code as follows:
ps> $ContentsWithLinebreaks-eq $ContentsWithLinebreaks 2.TrimEnd ("' R ' N")
True