How to snapshot objects exactly like default "Snapshot" that preserves hierarchy.

Hi all, I'm looking for a way to snapshot a hierarchy of objects usually a chain rig of bones while preserving their exact naming conventions and hierarchy.

I've tried snapshot in script as well as various copy methods but none of them seem to function like the default snapshot in max.

I need to do this via script. Can anyone help please?