I guess that you have the modern Dashboard content defined in your script statically. It would be better to define your content in a file and then use this file as input to your script. You can find a clear explanation of the process in this link:
https://thwack.solarwinds.com/product-forums/the-orion-platform/f/orion-sdk/92479/importing-exporting-modern-dashboards#mcetoc_1fgro1f7ua
I'm not a coder and don't know much about coding, so this could be a silly question.
I got func_ModernDashboards.ps1 from Github and attempted to load it with no changes. But getting above error.
I don't believe the ps1 file has to be updated.