I do not have an automated function, however... This may work until you build one or someone assists with one. Make sure and set results to text.
For tables:
sp_msforeachdb @command1 ='use ?
if ''?'' <> ''master'' and ''?'' <> ''model'' and ''?'' <> ''msdb'' and ''?'' <> ''tempdb''
begin
Select ''USE '' + (Select DB_name())
SELECT DISTINCT ''ALTER TABLE ['' + sys.schemas.name + ''].['' + sys.tables.name+ ''] REBUILD PARTITION = ALL WITH (DATA_COMPRESSION = PAGE, ONLINE = Off);''
FROM
sys.tables
INNER JOIN sys.partitions ON sys.partitions.object_id = sys.tables.object_id
INNER JOIN sys.schemas ON sys.tables.schema_id = sys.schemas.SCHEMA_ID
select ''GO''
end'
For indexes:
sp_msforeachdb @command1 ='use ?
if ''?'' <> ''master'' and ''?'' <> ''model'' and ''?'' <> ''msdb'' and ''?'' <> ''tempdb''
begin
Select ''USE '' + (Select DB_name())
SELECT DISTINCT ''ALTER INDEX ['' + sys.indexes.name + ''] ON ['' + sys.schemas.name + ''].['' + sys.tables.name+ ''] REBUILD PARTITION = ALL WITH ( STATISTICS_NORECOMPUTE = OFF, ONLINE = ON, SORT_IN_TEMPDB = OFF, DATA_COMPRESSION = PAGE )''
FROM
sys.indexes
INNER JOIN sys.tables ON sys.indexes.object_id = sys.tables.object_id
INNER JOIN sys.schemas ON sys.tables.schema_id = sys.schemas.schema_id
INNER JOIN sys.partitions ON sys.partitions.object_id = sys.indexes.object_id AND sys.partitions.index_id = sys.indexes.index_id
where sys.partitions.data_compression_desc <> ''PAGE''
select ''GO''
END'
.