Creating a Search Service Application and topology with PowerShell in SharePoint 2013 or 2016 – IN SAME APP POOL AS OTHER SERVICE APPLICATIONS

You can use this script to create a new search service application after you have removed your search service application.  WARNING: This creates the search service in an existing application pool named “SharePoint Hosted Services”.  Edit the $saAppPoolName, $serviceAppName, and $searchDBName to whatever you like making sure that the app pool already exists.  If it doesn’t exist, you should use the app pool that you run your other services, for example, excel services, visio, etc.