December 31, 2012

SharePoint Fundamentals: Document ID Service

The document ID feature creates identifiers that can be used to retrieve items independent of their current location. The document ID service that supports it generates and assigns document IDs.​ Read details in MSDN
Just go to site collection features and enable Document ID Service feature.
Once this feature is enabled, you will see configuration link in Site Settings.

You will be able to set some configuration related to DocumentID that is auto-generated in the Document ID Settings

And finally, when you upload any document to any of the document library in site collection, you will see document Id is automatically assigned to the library.

You must be thinking what is so good about this?
DocumentID service provides a web part to search any document by ID. You can place that web part in home page and anybody knowing(or not knowing) documentId that they are interested in can directly go do document whithout navigating site hierarchy. In case of multiple results list of documents will be displayed. This will work at site collection level for any document in site collection at any level deeper in site hierarchy.
2.Tobias Zimmergren's blog This blog presents much more details than what I copy pasted above! It is more than enough to know whatever you know as an analyst, programmer, tester or administrator.

If you have any questions you can reach out our SharePoint Consulting team here.

December 27, 2012

Powershell - Remove User account permissions from all sites

Use Cases:
When you create a site with unique permissions and break role inheritance at list or list item level, sharepoint will automatically add SHAREPOINT\System or site collection admin directly to Site Permissions. Here is the script that you can use to remove those users.
 function RemoveAccountFromAllSites ($siteURL, $accountName, [switch]$skipRootSite)
    #Get Site Collection
    $site = Get-SPSite $siteURL
    #Check if the accountName variable contains a slash - if so, it is an AD account
    #If not, it is a SharePoint Group
    $rootWeb = $site.RootWeb
    if ($accountName.Contains("\")) { $account = $rootWeb.EnsureUser($accountName) }
    else { $account = $rootWeb.SiteGroups[$accountName] }
    #Step through each site in the site collection
    $site | Get-SPWeb -limit all | ForEach-Object {
        #Check if the user has chosen to skip the root site - if so, do not change permissions on it
        if (($skipRootSite) -and ($site.Url -eq $_.Url)) { write-host "
Root site" $_.Url "will be bypassed" }
        else {
            #Check if the current site is inheriting permissions from its parent
            #If not, remove permissions on current site
            if ($_.HasUniqueRoleAssignments) {
                #write-host "
Removing account" $accountName "from site" $_.Url
            else {
                write-host "
Site" $_.Url "will not be modified as it inherits permissions from a parent site."
    #Display completion message and dispose of site object
    #write-host "
Operation Complete."
Script will check if site has unique permissions or not. Skips and don't do anything if site is not having unique permissions. Does what is expected if site is having unique permissions.
If you have any questions you can reach out our SharePoint Consulting team here.

Powershell - Creating log files for installation package

Use case:
It is general practice that we deliver wsp and powershell script to install it.
it is good practice to log whatever we show in screen to file so that it will be easy for sharepoint admin to send the result of installation.

 # Set Execution Policy 
Set-ExecutionPolicy unrestricted
$date     = Get-Date
#read parameters from command line
$CurrentDir= Split-Path -parent $MyInvocation.MyCommand.Definition 
$timeStamp = (Get-Date).ToString("yyyyMMddhhmmss") 
$logFile = $CurrentDir+ "\install_" + $timeStamp + ".log"
start-transcript -path $logFile -noclobber 
#add this at end of script
#this is to show stop-transcript 
Remove-PsSnapin Microsoft.SharePoint.PowerShell    
$CurrentDir will get installation folder. Start-Transcript is powershell command to copy whatever message printed to console to file provided in parameter.
You have to place your installation script between start and stop transcript commands and everytime you execute the script, it will generate a separate log file that will have all details.

If you have any questions you can reach out our SharePoint Consulting team here.

Powershell - Add newly added field to all views

#Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb -Identity "url of web"
#list of views which needs to be changed
$views = @("All Documents","View1","View2")

$list = $web.GetList("ListUrl")
foreach($vwName in $views)
    $vw = $list.Views[$vwName]
    #Add new field
        #position is 0 based
    Write-Host $vwName, "Updated"
If you have any questions you can reach out our SharePoint Consulting team here.