In this answer, to get the data I need from the restore headeronly command, and not creating a table for that, I use openrowset, and I have the path as parameter, so it can be changed.
Note that I use the character nchar(39) instead of apostrophes (').
I use WITH RESULT SETS in the code and I am running this on sql server 2016 and sql server 2019.
The script comes out like this:
Declare @path VARCHAR(260)
Declare @sql nvarchar(max)
Set @path='C:\backups\DIFF\my_server_AdventureWorks_diff.bak'
-- check contents of restore headeronly
-- marcello miorelli
select @sql=N'
select
a.ServerName
,a.DatabaseName
,a.BackupStartDate
,a.BackupFinishDate
,a.HasBackupChecksums
,a.IsCopyOnly
,a.Compressed
,a.CompressedBAckupSize
,a.BackupSize
,a.EncryptorThumbprint
,a.KeyAlgorithm
,a.EncryptorType
from openrowset(''SQLNCLI'',''Server=(local);Trusted_Connection=yes;'',
''SET FMTONLY OFF;
EXEC(''''
RESTORE HEADERONLY
FROM DISK = '''''''+nchar(39) + @path + nchar(39) +'''''''
'''')
WITH RESULT SETS(
(
BackupName nvarchar(128),
BackupDescription nvarchar(255),
BackupType smallint,
ExpirationDate datetime,
Compressed bit,
Position smallint,
DeviceType tinyint,
UserName nvarchar(128),
ServerName nvarchar(128),
DatabaseName nvarchar(128),
DatabaseVersion int,
DatabaseCreationDate datetime,
BackupSize numeric(20, 0),
FirstLSN numeric(25, 0),
LastLSN numeric(25, 0),
CheckpointLSN numeric(25, 0),
DatabaseBackupLSN numeric(25, 0),
BackupStartDate datetime,
BackupFinishDate datetime,
SortOrder smallint,
[CodePage] smallint,
UnicodeLocaleId int,
UnicodeComparisonStyle int,
CompatibilityLevel tinyint,
SoftwareVendorId int,
SoftwareVersionMajor int,
SoftwareVersionMinor int,
SoftwareVersionBuild int,
MachineName nvarchar(128),
Flags int,
BindingId uniqueidentifier,
RecoveryForkId uniqueidentifier,
Collation nvarchar(128),
FamilyGUID uniqueidentifier,
HasBulkLoggedData bit,
IsSnapshot bit,
IsReadOnly bit,
IsSingleUser bit,
HasBackupChecksums bit,
IsDamaged bit,
BeginsLogChain bit,
HasIncompleteMetaData bit,
IsForceOffline bit,
IsCopyOnly bit,
FirstRecoveryForkID uniqueidentifier,
ForkPointLSN numeric(25, 0),
RecoveryModel nvarchar(60),
DifferentialBaseLSN numeric(25, 0),
DifferentialBaseGUID uniqueidentifier,
BackupTypeDescription nvarchar(60),
BackupSetGUID uniqueidentifier,
CompressedBackupSize bigint,
Containment tinyint,
KeyAlgorithm nvarchar(32),
EncryptorThumbprint varbinary(20),
EncryptorType nvarchar(32)
))'') AS a'
print @Sql
exec (@sql)
and the result I get on my laptop is this:

This is how I took the backup for the result above:
--taking a backup with copy only and checking later the results on headeronly
backup database [AdventureWorks2019]
to disk='C:\backups\DIFF\my_server_AdventureWorks_diff.bak'
with copy_only,compression,no_checksum,stats=1,init,format
now with checksum and blocksize:
--taking a backup with copy only and checking later the results on headeronly - now with checksum and blocksize
backup database [AdventureWorks2019]
to disk='C:\backups\DIFF\my_server_AdventureWorks_diff.bak'
with copy_only,compression,checksum,stats=1,init,format,blocksize=4096
and the result for this one:
