After i've run the above script on the sharepoint server, it returned some errors. After some digging in the MSDN for the SPNavigationNode and SPNavigationNodesCollection classes, I modified the script to look like this: