is there a way to do it by command line in the same way that the third party tool does?
Sorry, but no not natively. The free space must be adjacent even with diskpart.
--please don't forget to upvote
and Accept as answer
if the reply is helpful--