Joel's SharePoint Architect Blog

SharePoint 2013 Training, Architecture, Administration and Development

Subscribe Subscribe  View Joel Jeffery's profile on LinkedIn
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk

Posts Tagged ‘PowerShell’

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.

IIS Showing Application Pools

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:

Extracting Passwords for Application Pools in IIS

Hope this helps someone!

Technorati Tags: PowerShell, SharePoint, SharePoint Administration

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! Smile

Technorati Tags: PowerShell, Search, SharePoint, SharePoint 2010, SharePoint Administration, SharePoint Administrator

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:

No PowerShell Equivalent to stsadm -o copyappbincontent

However, there is a PowerShell cmd-let called Install-SPApplicationContent:

Install-SPApplicationContent

Copies 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?

Technorati Tags: PowerShell, SharePoint, SharePoint 2010, SharePoint Administration, SharePoint Development

Renaming a Standalone SharePoint 2010 Server

OK. You never create standalone servers. I know. But, let’s just say you *did* have one, maybe for development or test, and let’s say you had such an environment on your laptop, and also let’s say your machine had an embarrassing name that you needed to change before you next demoed SharePoint stuff on it… OK, you get the picture. Smile

The Microsoft recommended steps are:

  1. Rename your PC using Computer properties:
    Renaming your PC
  2. Reboot.
  3. Run the PowerShell Command “Rename-SPServer

There is only one problem with this suggested method: it’s a steaming pile of nonsense.

The correct procedure would be:

  1. Rename your server using “Rename-SPServer”
  2. Rename the PC using Computer properties
  3. Reboot
  4. Rename your SQL instances
  5. Restart SQL
  6. iisreset /noforce

If you are unlucky enough to have tried to follow the official guidelines and renamed the PC before executing Rename-SPServer, you would get a message like this when trying to launch the SharePoint Management Shell:

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.

Then the correct recovery would be:

  1. Rename the server using “stsadm -o renameserver
  2. iisreset /noforce
  3. Rename your SQL instances.
  4. Restart SQL
  5. iisreset /noforce

Best of luck!

Technorati Tags: PowerShell, SharePoint, SharePoint 2010, SharePoint Administration

Here’s a common use case: a user in your company is complaining about how frequently they receive Alerts from content added to SharePoint 2010 Lists.

Yes, there are quite a few tools out there, and some folks suggest using Control Point or something expensive for this requirement. But in principle you don’t need those tools.

SharePoint 2010 is best administered by PowerShell. Here’s an example script that will reset all of the alerts for a specified user (e.g. “DOMAIN\JOEL”) to receive a weekly digest.

Start-SPAssignment –Global

Get-SPWeb http://sharepoint/* | ForEach-Object { $w = $_; ForEach($alert in $w.Alerts) { if($alert.User.UserLogin -eq “domain\joel”) { $alert.AlertFrequency = “Weekly”; $alert.Update(); } } }

Stop-SPAssignment -Global

Enjoy!

Post Script:

Top tip from Andrew, one of my students. Why not train users to manage alerts for themselves? Outlook has the Manage Rules & Alerts feature to make the task easier:

Manage SharePoint Alerts from Outlook

 

Technorati Tags: PowerShell, SharePoint 2010, SharePoint 2010 Training, SharePoint Administration