use msdb
DECLARE @ServerDest varchar(100) = 'Source_server_name'
;WITH CTE_Recursiv (parentfolder,foldername,folderid,Level)
as
(
SELECT
CAST('/' as sysname) parentfolder,
foldername folder,
folderid ,
0 Level
FROM
sysssispackagefolders
WHERE
parentfolderid = '00000000-0000-0000-0000-000000000000'
UNION ALL
SELECT
CAST(C.parentfolder + C.foldername +'/' as sysname) parentfolder,
f.foldername folder,
f.folderid ,
C.Level + 1 Level
FROM
sysssispackagefolders f
INNER JOIN CTE_Recursiv C on C.folderid = f.parentfolderid
)
SELECT
'dtutil /FC SQL;"' + parentfolder + '";"' + foldername + '" /SourceS ' + @ServerDest Comando
FROM
CTE_Recursiv
ORDER BY
Level,
parentfolder