Thursday, December 5, 2013

Fix a Secure Store service or any SharePoint service stuck on starting or stopping

change the "Server Name" in the script.  To stop change Provision() to UnProvision()

one thing to note is that if the status is provisioning, then you'll most likely need to Provision() then UnProvision().

Also all you need to do is get the service instance for other services by the type or name. 

--------------------------------------------------------------
add-pssnapin MIcrosoft.SharePoint.Powershell

Function MatchComputerName($computersList, $computerName)
{
                If ($computersList -like "*$computerName*") { Return $true; }
    foreach ($v in $computersList) {
      If ($v.Contains("*") -or $v.Contains("#")) {
            # wildcard processing
            foreach ($item in -split $v) {
                $item = $item -replace "#", "[\d]"
                $item = $item -replace "\*", "[\S]*"
                if ($computerName -match $item) {return $true;}
            }
        }
    }
}

           $secureStoreServiceInstances = Get-SPServiceInstance | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance])}
            $secureStoreServiceInstance = $secureStoreServiceInstances | ? {MatchComputerName $_.Server.Address "Server Name"}
           
            Write-HOst $secureStoreServiceInstance.Status

            $secureStoreServiceInstance.Provision()