Because get-content returns a file as an array of strings, the array can be piped into where-object to search for specific lines that match a criteria (such as a regular expression).
In order to start with the n-th line rather than the first one, $_[0] must be changed accordingly.
Reading a file in batches of n bytes
In combination with -encoding byte («ordinary» PowerShell) or -asByteStream (PowerShell Core), -readCount and -totalCount allows to read a file in batches of n bytes:
It is possible to get the content non-filesystem providers such as the function provider:
PS C:\> get-content function:/mkdir
Variables as special kinds of items
Because a variable is just a special kind of an item, the value (that is: the content) of a variable can be determined with get-content.
The following example demonstrates that even indirection is possible: get-content variable:\$varName returns the value of the variable whose name is $varName:
In order to get the content of a file as a byte array, get-content must be used together with the parameters -encoding byte -raw (PowerShell Desktop) or -asByteStream (PowerShell Core).
Hexadecimal representation of a file
The canonical way to get the content of a file in hexadecimal representation is the cmdLet format-hex.
format-hex also prints a header and the printable characters which sometimes is not what I want.
If the content of a file needs to be returned as a simple hexadecimal string, get-content along with -encoding byte and -raw might achieve this:
#
# Get the content of a file as a byte array:
#
$arrayOfBytes = get-content -encoding byte -raw file.txt
$arrayOfBytes.GetType().FullName
#
# System.Byte[]
#
# Format each element of the byte array to a hexadecimal
# representation, resulting in an array of strings, each
# of which is two characters wide:
#
$arrayOfHex = $arrayOfBytes.foreach( { '{0:X2}' -f $_ } )
#
# Join the elements of the string array to create
# one string:
#
$hexString = $arrayOfHex -join ''
#
# Print the string
#
$hexString
#
# 4142430A4445460A4748490A