We were doing an install today with 1 App Server and 1 WFE. On the WFE our 'WebApplications' node was empty as this was configured in the App Server XML config (we found if it was primed then the script would bomb out saying that the mysite already existed).
The script was failing just after creating the search share (we needed this as the WFE was going to be a query server).
At the line '$CrawlStartAddresses = $PortalURL+":"+$PortalPort', if $PortalURL and $MySiteURL is empty, then line 2760 (Get-SPEnterpriseSearchServiceApplication) will fail. At line 2763 there appears to be the end of an if block without
a starting if condition. Please check to see if there is something wrong with this block of code.