Wednesday, May 22, 2013

How to find the template name of SharePoint site?

General Questions:

I have SharePoint site which is fully customized I would like to know the template name of site, because the SharePoint is created by some body else I don't know which template the guy had selected (like team site, blank site, publishing, collaboration site etc. while creating the site.

Answer

  • Code Snippet
    <%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
    <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>

    <script runat="server">
    protected override void OnLoad(EventArgs e){
    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
    using (SPWeb thisWeb = this.Web)
    {
    lblWebTempalte.Text = thisWeb.WebTemplate;
    lblWebTemplateID.Text = thisWeb.WebTemplateId.ToString();
    }
    });
    }
    </script>
    <asp:Content ID="Main" runat="server" contentplaceholderid="PlaceHolderMain" >
    <p>
    Web Template: <asp:Label ID="lblWebTempalte" runat="server" />
    </p>
    Web Template ID: <asp:Label ID="lblWebTemplateID" runat="server" />
    </asp:Content>

    <asp:Content ID="PageTitle" runat="server" contentplaceholderid="PlaceHolderPageTitle" >
    Site Template Information
    </asp:Content>

    <asp:Content ID="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
    Site Template Information
    </asp:Content>

    Please follow the steps to know the template name of sharepoint site:
    • Save the code snippet code as .aspx page ( eg:webtemplate.aspx) to your layouts folder (usually C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS)
    • Once the page is saved you can access it from any of your sharepoint sites via http://servername/_layouts/webtemplate.aspx
    • Compare the web template ID with the below List of MOSS 2007 Template ID Information

    List of MOSS 2007 Template ID Information
    0 - GLOBAL (SetupPath=global) - "Global template"
    1 - STS - "windows SharePoint Services Site", "Team Site", "Blank Site", "Document Workspace"
    2 - MPS - "Basic Meeting Workspace", "Blank Meeting Workspace", "Decision Meeting Workspace", "Social Meeting Workspace", "Multipage Meeting Workspace"
    3 - CENTRALADMIN - "Central Admin Site"
    4 - WIKI - "Wiki Site"
    7 - BDR - "Document Center"
    9 - BLOG - "Blog"
    20 - SPS (OBSOLETE) - "SharePoint Portal Server Site"
    21 - SPSPERS - "SharePoint Portal Server Personal Space"
    22 - SPSMSITE - "Personalization Site"
    30 - SPSTOC (OBSOLETE) - "Contents area Template"
    31 - SPSTOPIC (OBSOLETE) - "Topic area template"
    32 - SPSNEWS (OBSOLETE) - "News area template"
    33 - SPSNHOME (SubWebOnly) - "News Home template"
    34 - SPSSITES - "Site Directory area template"
    36 - SPSCOMMU (OBSOLETE) - "Community area template"
    38 - SPSREPORTCENTER - "Report Center Site"
    39 - CMSPUBLISHING (SetupPath=SiteTemplates\PUBLISHING) - "Publishing and Team Collaboration Site"
    40 - OSRV (SetupPath=SiteTemplates\OSRV) - "Shared Services Administration Site"
    47 - SPSPORTAL - "Corporate Intranet Site"
    50 - SRCHCEN - "Search Center"
    51 - PROFILES - "Profiles"
    52 - BLANKINTERNETCONTAINER - "Internet Presence Web Site"
    53 - BLANKINTERNET - "Publishing Site", "Press Releases Site", "Publishing Site"
    54 - SPSMSITEHOST - "My Site Host"
    90 - SRCHCENTERLITE (SetupPath=SiteTemplates\SRCHCENTERLITE) - "Search Center Lite"
    6221 - PWA (SetupPath=SiteTemplates\PWA) - "Project Web Access Site"
    6215 - PWS (SetupPath=SiteTemplates\PWS) - "Project Workspace"
    14483 - OFFILE - "Records Repository", "Records Repository"

    For more information please visit
    http://blog.rafelo.com/2008/05/determining-site-template-used-on.html
    http://www.frontpages-web-hosting.net/forums/microsoft-office-sharepoint-server-2007-moss-2007-development-topics/486-moss-2007-template-id-information.html

Reference
http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/721bec39-2d32-4bbc-9094-a021a0d06dcb


Determining size of SharePoint sites / site collections



General Question

How to get the size (in bytes) of each site collection in SharePoint?

Answers

stsadm -o enumsites -url http://url

Example

<Sites Count="1">
  <Site
    Url="http://url"
    Owner="DomainName\user"
    SecondaryOwner="DomainName\user2" 
    ContentDatabase="WSS_Content_DB"
    StorageUsedMB="13756"
    StorageWarningMB="0"
    StorageMaxMB="0" />
</Sites>


Save to Notepad (.txt) file

stsadm -o enumsites -url "http://url"  > c:\sites.txt



Monday, May 20, 2013

DisableLoopbackCheck registry key


Issues: 1
I was working on a server and we were trying to access the local SharePoint site http://127.0.0.1 or http://NameofLocalServer/pages/default.aspx and I was constantly prompted for the username and password. In SharePoint 2007/2010, it can really annoy you by not accepting your username password credentials in the popup window.
Issues: 2
You receive error 401.1 when browsing a local IIS with Windows Authentication
This usually happens when you try browsing your ADFS from within the same machine where ADFS is running. This is not related to ADFS, but it's an issue with Windows Integrated Authentication in IIS in general.
To fix this you have to set a registry key on the ADFS machine.
To set the DisableLoopbackCheck registry key yourself, follow these steps:
1.      Click Start, click Run, type regedit, and then click OK.
2.      In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
3.      Right-click Lsa, point to New, and then click DWORD Value.
4.      Type DisableLoopbackCheck, and then press ENTER.
5.      Right-click DisableLoopbackCheck, and then click Modify.
6.      In the Value data box, type 1, and then click OK.
7.      Quit Registry Editor, and then restart your computer.


Here is a PowerShell one-liner to change that key:

Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa" -name "DisableLoopbackCheck" -value 1 -Type DWORD

Reference


Friday, May 17, 2013

List All SharePoint 2010 PowerShell Commands


Use this PowerShell command to output a list of all cmdlets that are found within the SharePoint 2010 namespace:


PS C:\> Get-Command -PSSnapin "Microsoft.SharePoint.PowerShell" | select name, definition | format-list > C:\SP2010_PowerShell_Commands.txt

Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” | select name, definition | format-list > C:\SP2010_PowerShell_Commands.txt

How to get a list of all Managed service accounts on a SharePoint 2010


We can use the below Powershell cmd to get the all Managed service accounts on a SharePoint 2010

PS C:\> Get-SPManagedAccount





But we have some issues like above and PowerShell truncates table by default.
Here are the results of that command, showing a table with column names that span multiple lines and rows with data that is not useful:

If you try to solve this problem by looking at the help for Format-Table, you may come across the AutoSize parameter.  The AutoSize parameter allows you to tell PowerShell that you want the formatter to automatically size the table columns, showing as much data as possible.  Here is what happens if you add the AutoSize parameter to the same command you just ran:

PS C:\> Get-SPManagedAccount | Format-Table -Property * -AutoSize





This is on the right track for what you are after, but notice the warning text that is output at the top of the resulting table.  It indicates that 10 columns do not fit into the display and were removed.  If you pipe the results of this command to Out-File, PowerShell will simply pass what you see on the screen to the file you are writing to, which is not sufficient for your needs.


Solution: 

Using Parameters for Format-Table like below

PS C:\> Get-SPManagedAccount | Format-Table -Property UserName
,PasswordExpiration, AutomaticChange –AutoSize

Using Out-String and width if you have many parameters to pass

PS C:\Users\sg-tst-spsql> Get-SPManagedAccount | Format-Table -Property *
 -AutoSize | Out-String -Width 4096




The above command that might not look very useful either, but look what happens when you take this one step further and pass the results to Out-File.  Here is the command to do this:
3. Using Out File

Get-SPManagedAccount 
| Format-Table -Property * -AutoSize | Out-String -Width 4096 
| Out-File C:\ServiceAccount.txt





Opening the resulting ServiceAccount.txt file shows the following contents:


Note: In your notepad, Go to Format and Uncheck the Word Wrap if its checked to get the above result.

Reference:

How do I run a .ps1 file (Powershell script) from within Powershell?


Problem:

PS C:> C:\Test.ps1

File C:\Test.ps1 cannot be loaded. The file C:\Test.ps1 is not digitally signed. The script will not execute on the system. Please see "get-help about_signing" for more details…
At line:1 char:13 + .Test.ps1 <<<<


Solution:

Run the below command

PS C:\> Get-ExecutionPolicy
Restricted

It will return the policy you are currently running with. (For ex: Restricted)

Actually, there are three options for the execution policy that you can set:
·         AllSigned (default): all scripts need to be signed.
·         RemoteSigned: Only scripts downloaded from the internet must be signed.
·         Unrestricted: Any scripts will run without being signed.
I have changed the my policy using the below command like RemoteSigned


PS C:\> Set-ExecutionPolicy RemoteSigned

Then I have run the below Get-ExecutionPolicy command and I got ByPass

PS C:\> Get-ExecutionPolicy
ByPass

Finally, I can able to run the Test.ps1 file successfully.




Monday, May 13, 2013

How to shrink SQL / SharePoint database / log files



1. First to be on the safe side, let’s back it up (this step is optional)

Select New Query

Type the following:
BACKUP LOG [Sharepoint_Config] TO DISK='D:\SharePointConfigLogBackup.bak'
GO

Where SharePoint_Config is the name of your config database file and D:\SharePoinConfiglogbackup.bak is the location and file name of where you’ll make the backup.

And click Execute


2. Use the following simple three steps to shrink your database


USE [master]  
GO  
ALTER DATABASE [SharePoint_Config] SET RECOVERY SIMPLE WITH NO_WAIT  
GO  

Click Execute

USE [Sharepoint_Config]  
GO  
DBCC SHRINKFILE ('SharePoint_Config_log')  
GO  

Click Execute


ALTER DATABASE [SharePoint_Config] SET RECOVERY FULL WITH NO_WAIT 
GO
USE [Sharepoint_Config]  
GO

Click Execute


3. If you get the below error when you run the shrink file query

Msg 8985, Level 16, State 1, Line 1
Could not locate file 'tempdb_log' for database 'tempdb' in sys.database_files. The file either does not exist, or was dropped. 

Use the below commends to shrink those system database files

USE tempdb;
GO
SELECT file_id, name FROM sys.database_files;
GO
DBCC SHRINKFILE (2, TRUNCATEONLY);

Here tempdb is your system database files name.