Joel's SharePoint Architect Blog
SharePoint 2013 Training, Architecture, Administration and Development
Subscribe
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk
Posts Tagged ‘SharePoint’
Recovering Passwords for SharePoint 2010 Farm, Web Application and Service Application Accounts
Ever lost your Farm password?
Farm Password Recovery in SharePoint 2010
The other day I was asked by a customer, “hey, would you happen to have a copy of our Farm password anywhere?”
No, I didn’t. And it would kind of be bad if I did!
However, I could recover SPFarm passwords and recover other Application Pool account passwords for them, once Remote Desktopped in to one of the SharePoint servers.
If you want to recover the Farm password, you need to sign in with a Local Administrator account on a server running Central Admin.
If you want to recover one of the Web Application or Service Application passwords, then you need to log in to one of those servers instead.
IIS 7.x runs Central Admin in the context of an Application Pool running under the Farm Account credentials. Similarly, Web Applications and Service Applications run in App Pools with their own credentials.
To recover any of these, start up an Administrative command prompt or PowerShell window, and IIS Manager 7.x.
In IIS Manager, you need to find out the name of the Application Pool.
For Central Admin, that would be:
SharePoint Central Administration v4
But we can also uncover the passwords for other Application Pools, e.g.:
SharePoint – 80
SharePoint Web Applications
e4b4b94050634ad2863ad7d7d17c3a17
Next, at the command prompt (or PowerShell) you can use the IIS appcmd.exe to request the Password field from the ProcessModel section of the applicationHost.config file. For example, in PowerShell (on ONE LINE!):
&$env:windir\\system32\\inetsrv\\appcmd.exe list apppool
"SharePoint Central Administration v4" /text:ProcessModel.Password
An example run is shown below:
Hope this helps someone!
Automatically Generating Thesaurus Files from Taxonomy for SharePoint Search
A while ago, a student of mine asked if it was possible to use the taxonomic alternative labels from the Managed Metadata Service as thesaurus items in SharePoint Server Search.
There’s no built-in way to do this, but it is possible to generate the required Xml with a little PowerShell.
The Concept
The Term Store contains Term Group, which content Term Sets, which in turn contain nested Terms. Each Term can have (optional) synonyms called Labels.
If we find all the Terms with Labels, we can write them out in the correct format as a chunk of Xml, and pipe it into a thesaurus file.
Thesaurus files for SharePoint Server Search are kept under the file path:
%ProgramFiles%\Microsoft Office Servers\14.0\Data\Office Server\Applications\GUID-query-0\Config
A sample thesaurus file is shown below:
<XML ID="Microsoft Search Thesaurus"> <thesaurus xmlns="x-schema:tsSchema.xml"> <diacritics_sensitive>0</diacritics_sensitive> <expansion> <sub>Internet Explorer</sub> <sub>IE</sub> <sub>IE8</sub> </expansion> <replacement> <pat>NT5</pat> <pat>W2K</pat> <sub>Windows 2000</sub> </replacement> </thesaurus> </XML>
You can see the rationale for how this file works on and how to manage thesaurus files at TechNet.
The Script
The script below shows the principle. It iterates over the Terms in each Term Store and finds their Labels. Where the Label is not the same as the name of the Term itself, it represents a synonym and we add it to the Xml.
function Extract-SPThesaurusFromTermLabels
{
param([string] $webUrl);
$ts = Get-SPTaxonomySession -Site $webUrl;
Write-Output "<XML ID='Microsoft Search Thesaurus'>";
Write-Output "<thesaurus xmlns='x-schema:tsSchema.xml'>";
$ts.TermStores |
% { $_.Groups |
% { $_.TermSets |
% { $_.Terms |
% { $_.Labels |
? {$_.Term.Name -ne $_.Value} |
% {
Write-Output ("<expansion><sub>" + $_.Term.Name +
"</sub><sub>" + $_.Value + "</sub><expansion>");
}
}
}
}
};
Write-Output "</thesaurus>";
Write-Output "</XML>";
}
You can then pipe the output of this command to an Xml file, and optionally use this in the place of your existing Thesaurus file with something like this:
Extract-SPThesaurusFromTermLabels http://sharepoint > tsLANG.xml
As always, please back up your original Thesaurus files and check the output of this before you use it! ![]()
SPSite and the Recycle Bin in SharePoint 2010 SP1
Service Pack 1 for SharePoint 2010 brought us a much-needed feature – the recycle bin for SPWeb and SPSite objects.
Recycling SharePoint Sites
If you want to move an SPWeb into the recycle bin programmatically, there’s the fairly-straightforward SPWeb.Recycle() method. Once you’ve invoked this, you can restore the SPWeb from the SPSite.RecycleBin object with the Restore() method.
But, how do I recycle and restore a site collection (SPSite)?
Recycling SharePoint Site Collections
Firstly, there’s no Recycle() method on the SPSite object. Invoking Delete() removes the SPSite immediately, unless you pass in an argument to get it to perform a gradual delete. The gradual delete process is carried out by the “Gradual Delete Timer Job”, whose purpose is to delete site collections efficiently 1000 database rows at a time.
However, it also has some nice side effects. The timer job only deletes site collections that were deleted more than 30 days ago (or whatever the recycle bin age is configured for the web application). In that intermediate time, the deleted site collections are available to be restored.
You can get at the deleted sites via the GetDeletedSites method of the SPWebApplication object. This returns a collection of SPDeletedSite objects, on which you can invoke the Restore method.
Sample Code
// get our web application SPWebApplication webapp = SPWebApplication.Lookup(new Uri("http://sharepoint")); // find our deleted site collection foreach (SPDeletedSite site in webapp.GetDeletedSites("http://sharepoint/sites/myoldsite")) { //restore it! site.Restore(); }
Enjoy!
STSADM copyappbincontent vs. Install-SPApplicationContent
The purpose of STSADM’s “copyappbincontent” command is:
stsadm –o copyappbincontent
Copies Web application–specific files, such as page resource (*.resx) files from their respective locations in the 12\CONFIG folder to the correct location in each Web application on the computer.
According to TechNet, there is no equivalent PowerShell cmd-let http://technet.microsoft.com/en-us/library/ff621081.aspxt:
However, there is a PowerShell cmd-let called Install-SPApplicationContent:
Install-SPApplicationContentCopies shared application data to existing Web application folders.
Now that sounds pretty similar.
I’ve tried this out – making a custom layouts.sitemap.xml file, and invoking Install-SPApplicationContent. It copies/merges the sitemap into the correct place under inetpub\wwwroot\wss\VirtualDirectories\*\_app_bin.
So, how dissimilar are they? I’ve heard it said that the PowerShell version won’t apply your changes to the whole farm, only the current server. But surely, that’s what stsadm does too?
Let’s use the rather fantastic open-source ILSpy replacement for Reflector to reflect over the code,
STSADM’s copyappbincontent decompiled
// Microsoft.SharePoint.StsAdmin.SPCopyAppBinContent public override void Run(StringDictionary keyValues) { SPServiceInstance sPServiceInstance = SPWebServiceInstance.LocalContent; if (sPServiceInstance != null && sPServiceInstance.Status == SPObjectStatus.Online) { SPWebService contentService = SPWebService.ContentService; contentService.ApplyApplicationContentToLocalServer(); } sPServiceInstance = SPWebServiceInstance.LocalAdministration; if (sPServiceInstance != null && sPServiceInstance.Status == SPObjectStatus.Online) { SPWebService administrationService = SPWebService.AdministrationService; administrationService.ApplyApplicationContentToLocalServer(); } }
Microsoft.SharePoint.PowerShell’s Install-SPApplicationContent decompiled
if (sPWebServiceInstance.Status == SPObjectStatus.Online) { SPWebService administrationService = SPWebService.AdministrationService; ServiceHelper.TryToControlService("W3SVC", false, out flag, out flag2); administrationService.ApplyApplicationContentToLocalServer(); } if (null != SPWebServiceInstance.LocalContent) { if (SPWebServiceInstance.LocalContent.Status == SPObjectStatus.Online) { ServiceHelper.TryToControlService("W3SVC", false, out flag3, out flag4); SPWebService contentService = SPWebService.ContentService; contentService.ApplyApplicationContentToLocalServer(); } }
Conclusion
So, there you have it. Like two completely dissimilar things… in a pod.
To be clear: you need to invoke either of these methods on each server in your farm to deploy content from the 14 hive to the IIS virtual directories.
Or have I missed something?
