What's your on-prem Exchange server version? The supported ways to migrate public folder to exchange online are introduced in the official documents below:
Use batch migration to migrate Exchange Server public folders to Exchange Online
Use batch migration to migrate legacy public folders to Microsoft 365 or Office 365 and Exchange Online
We can see that the script Sync-ModernMailPublicFolders.ps1 synchronizes mail-enabled public folder objects between your Exchange on-premises environment and Microsoft 365 or Office 365. So we could mail disable other public folders so that they will not be synced to o365.
Also you could use Outlook PST export to migrate the public folder as well. However please notice that: We recommend that you don't use Outlook's PST export feature to migrate public folders to Microsoft 365, Office 365, or Exchange Online. Public folder mailbox growth in Exchange Online is managed using an auto-split feature that splits the public folder mailbox when it exceeds size quotas. Auto-split can't handle the sudden growth of public folder mailboxes when you use PST export to migrate your public folders, and you may have to wait for up to two weeks for auto-split to move the data from the primary mailbox. We recommend that instead you use the cmdlet-based instructions in this article to migrate your public folders.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.