Re-creating the SharePoint Web Services Site

https://blogs.msmvps.com/haarongonzalez/how-to-restore-the-sharepoint-web-services-iis-web-site-if-accidently-deleted/

The above blog post explains that it is possible to, erroneously, remove the SharePoint Services website from the file system when there are extended zones in play for a web application where the extended zone was created using the option of ‘Use an existing IIS web Site’.

The problem becomes, if the Site that the SharePoint Web Services uses is allowed to be used for a new extension off of an existing web application, and, that extended zone is at some later point deleted, the IIS site (SharePoint Web Services) root folder on the is also deleted.  This action of removing the extended zone, removes the site in IIS as it has already removed the file system root folders.

 

Here are the locations of the root folders for the various levels of SharePoint

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\WebServices\        – SharePoint 2010

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\WebServices\        – SharePoint 2013

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\WebServices\        – SharePoint 20160

Running this from an administrative, SharePoint Management Shell has fixed the issue of the SharePoint Web Services site having been deleted.

$webservice = [System.Type]::GetType("Microsoft.SharePoint.Administration.SPIisWebServiceSettings, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
 
 
$Instance = $webservice::Default
$Method = $webservice.GetMethod("ProvisionLocal", "Instance, NonPublic", $null, @(), $null) 
$Method.Invoke($Instance, $null)
$Method = $webservice.GetMethod("Provision", "Instance, Public", $null, @(), $null) 
$Method.Invoke($Instance, $null)

Once you have ran the above script, we should have “SharePoint Web Service” under IIS with only few information.
now we need to get all the respective VD in IIS.

This code should provision all of the service application endpoints, and it needs to be ran after running the above code:

Get-SPServiceApplication | ForEach-Object {$_.Provision()}

CODE CREDIT: https://blogs.technet.microsoft.com/vinitt/2011/05/13/how-to-get-back-the-sharepoint-webservices-applicaion-in-iis-if-deleted-sharepoint-2010/

Option 2

Run this code:

$h = Get-SPServiceHostconfig

$h.Provision()

$services = Get-SPServiceApplication

foreach ($service in $services) { $service.provision();
write-host $service.name}