Determining the version of a PDF document
If you have a Portable Document
Format (PDF) file and wish to determine the version of the PDF standard
used for the document, that information is stored in the first line of the
file. You can open the file with a
text editor, such
as the Windows
Notepad application on a Microsoft Windows system and view
the first line to determine the PDF version used for the file.
You will see %PDF-x.y
where x.y is the
version of the PDF standard used in the creation of the file,
e.g., %PDF-1.7
for version 1.7.
On a Microsoft Windows system, you could also open a
PowerShell window (you can type PowerShell
in the Windows Search field and click on the
application when you see it returned in the list of
results) and use the Get-Content
cmdlet
and the -First
parameter followed by the number one.
E.g.:
PS C:\> Get-Content "July 2024 Newsletter.pdf" -First 1
%PDF-1.7
PS C:\>
Related:
-
PowerShell Get-Content equivalents to Linux head and tail commands
Date: March 22, 2024
[/os/windows/PowerShell]
permanent link
Calculating a hash value for a file with Get-FileHash
The PowerShell cmdlet
Get-FileHash provides a
cryptographic hash function that will allow you to determine a
hash value of a file on a Microsoft Windows system. By default,
the cmdlet
uses the SHA-256 hash
function, but you can specify other functions, such as
MD5, using the
-Algorithm
parameter. You can change the output to a list
format by
piping the output
of the cmdlet to Format-List
.
PS C:\users\public\downloads> Get-FileHash ".\rel_x64_Xming-7-7-1-1-setup.exe"
Algorithm Hash Path
--------- ---- ----
SHA256 B7B4C0A191E315686A2481DCC8BBB27D6D7A156FBF689768E48CF08207B86560 C:\users\public\downloads\rel...
PS C:\users\public\downloads> Get-FileHash ".\rel_x64_Xming-7-7-1-1-setup.exe" | Format-List
Algorithm : SHA256
Hash : B7B4C0A191E315686A2481DCC8BBB27D6D7A156FBF689768E48CF08207B86560
Path : C:\users\public\downloads\rel_x64_Xming-7-7-1-1-setup.exe
PS C:\users\public\downloads> Get-FileHash -Algorithm MD5 ".\rel_x64_Xming-7-7-1-1-setup.exe"
Algorithm Hash Path
--------- ---- ----
MD5 BA200636A596A84E0877901CE89D1C2E C:\users\public\downloads\rel...
PS C:\users\public\downloads>
[ More Info ]
[/os/windows/PowerShell]
permanent link
PowerShell Get-Content equivalents to Linux head and tail commands
The Windows
PowerShell
Get-Content
cmdlet can provide the equivalent to the Unix/Linux
head and
tail commands.
E.g., suppose a file named
somefile.txt
contains the following
ten lines:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
line 8
line 9
line 10
The following Get-Content commands could be used to obtain the first 5
and the last 5 lines in the file.
PS C:\Users\Arnold\Documents> Get-Content somefile.txt -Head 5
line 1
line 2
line 3
line 4
line 5
PS C:\Users\Arnold\Documents> Get-Content somefile.txt -Tail 5
line 6
line 7
line 8
line 9
line 10
PS C:\Users\Arnold\Documents> Get-Content somefile.txt -TotalCount 5
line 1
line 2
line 3
line 4
line 5
C:\Users\Arnold\Documents>
The TotalCount
parameter can function like the
Head
parameter and will return the first x number of
lines specified with x being 5 in the example above. You can also
use it to obtain a specific line, though. E.g., if you wished to see the
7th line in the file, you could use the command below.
PS C:\Users\Arnold\Documents> (Get-Content Somefile.txt -TotalCount 7)[-1]
line 7
PS C:\Users\Arnold\Documents>
By default the delimiter for lines is the
newline, aka end-of-line
character, \n
, but you can change that with the -Delimiter
parameter.
References:
-
Get-Content
Microsoft Learn
[/os/windows/PowerShell]
permanent link
Determining the Serial Number of a Disk Drive with PowerShell
If you need to determine the serial number of a hard disk drive (HDD)
attached to a Microsoft Windows system, you can do so from a
PowerShell
window using the cmdlet Get-Disk (you can open a
PowerShell window by typing PowerShell
in the Windows "Type here to
search field on a Windows 10 system and then selecting the app when it is
returned in the list of search results). If you just want a list of drives
attached to the system by a USB
connection, you can pipe
the output of the cmdlet to the