Showing posts with label Power Shell. Show all posts
Showing posts with label Power Shell. Show all posts

Aug 17, 2013

Migrate SharePoint 2010 to 2013


In this article, we will learn how to migrate SharePoint 2010 to SharePoint 2013. This migration is applicable for OOTB features migration not for Custom Solution migration to SharePoint 2013.
Steps:
      1. Change the Authentication mode of SharePoint 2010 application to Claims using the PowerShell command
$WebAppName = ""
$account = ""
$wa = get-SPWebApplication $WebAppName
Set-SPwebApplication $wa AuthenticationProvider (NewSPAuthenticationProvider) Zone Default
2.   We have to take the backup of solutions (WSP) from SP 2010 and deploy it in the SP 2013 farm. Use the following PowerShell command to back up the WSP
$farm = Get-SPFarm
$file = $farm.Solutions.Item("Backup.wsp").SolutionFile
$file.SaveAs("C:\Backup.wsp")
3.   Now, deploy the solution to the SP 2013 farm using the following command:
Add-SPSolution -LiteralPath "C:\Backup.wsp" 
(rebuilding the solution in Visual Studio 2012 is required sometimes)
     4.  Now take the backup of Content DB from SP 2010 and attach in SP 2013 database server
Note: This will automatically update the DB schema for SQL server 2012 (which is previously lower version in SP 2010)
    5.   Create a new web application in SP 2013 and after creating the web application detach the Content DB (which is newly created for SP 2013 now)
    6.   Now, attach the backup Content DB (taken from SP 2010) using the following command
Mount-SPContentDatabase -name -WebApplication 
Note: This will automatically update the Dictionary and other required update for SP 2013.
    7.   Now deploy the List templates and other backups from SP 2010 if required.
Note: This is applicable only for OOTB solutions. If you have custom solutions, then you have to re-build the code using Visual Studio 2012 and then deploy the solution.
Hope this helps you and please free to comment and share this post.

Jan 7, 2013

Export SharePoint Group to Excel using PowerShell

$siteUrl="SiteURLHere"
$groupName="GroupNametoExport"
$Output = @("GroupName|Name|Login|Email|Department|Title")
$web = Get-SPWeb $siteUrl
$site = $web.Site
$rootWeb = $site.RootWeb
$UserList = $rootWeb.Lists["User Information List"]
$web.SiteGroups[$groupName].Users|%{$user = $UserList.GetItemById($_.ID)
if($user -ne $null)
{
$JobTitle = $user["JobTitle"]
$Department = $user["Department"]
}
$Output += ($groupName+"|"+$_.Name+"|"+$_.UserLogin+"|"+$_.Email+"|"+$ Department +"|"+$JobTitle)
}
$rootWeb.Dispose()
$web.Dispose()
$site.Dispose()
$Output > "D:\MembersExport.csv"

Import Excel to SharePoint List using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$contents = Import-CSV ‘C:\Input.csv' -header("Employee ID", "Employee Name")
# Web URL
$webURL = “SITEURL here”
$web = Get-SPWeb -Identity $webURL
$listName = "ListNameHere"
$list= $web.Lists["$listName"] 
# Iterate for each list column
foreach ($row in $contents )
{
    $item = $list.Items.Add();
    $item["Employee ID"] = $row.GroupName
    $item["Employee Name"] = $row.Permissions
    $item.Update()
}
Write-Host -ForegroundColor green "List Updated Successfully"
$web.Dispose()

Jan 6, 2013

Import Users from Excel to SharePoint using PowerShell

# Import the .csv file, and specify manually the headers, without column name in the file 
$userList=IMPORT-CSV C:\UserToUpload.csv -header("GroupName","UserName")

#Get the site name to the variable
$web = Get-SPWeb SiteURLHere

foreach ($user in $userList)
{
$groupName = $web.SiteGroups[$userList.group]
$user = $web.Site.RootWeb.EnsureUser($userList.user)
$groupName.AddUser($user)
}
Write-Host -ForegroundColor green "Users Added Successfully"
}
$Web.Dispose()

Add Users to SharePoint Group using PowerShell

#Get the site name to the variable
$web = Get-SPWeb SitURLHere
#Get the group name to the variable
$groupName = $web.SiteGroups["Group Name Here"]
#Assign user to variable
$user = $web.Site.RootWeb.EnsureUser(“User ID Here”)
#Add user to group 
$groupName.AddUser($user)
Write-Host -ForegroundColor green "User Added Successfully";

Aug 28, 2012

Advantage of PowerShell over STSADM

In SharePoint 2010, new concept called Power Shell is introduced. The main adavantage of using Windows Power Shell over STSADM is follows:
  • Windows PowerShell is built on the Microsoft .NET Framework and accepts and returns .NET Framework objects. Hence, can interact with .Net objects directly.
  • Here we use commandlets (cmdlet) instead of commands. Commandlet is a instance of .Net objects
  • We can automate the tasks using power shell scripts.
  • Windows PowerShell also gives you access to the file system on the computer and enables you to access other data stores, such as the registry and digital signature certificate stores.

Dec 23, 2011

stsadm Command for Creating Backup and Restoring a Site in SharePoint

In this article, we will discuss how to take a backup and restore it using the stsadmn command in SharePoint (WSS 3.0, MOSS 2007).
In SharePoint 2010, we use Power Shell instead of this command.
Before going for that let’s discuss about stsadm
What is stsadm command?
It is a command line tool for administration of SharePoint sites.
Where it is located in the server?

Normally, it is present in the following path

C:\ProgramFiles\Common Files\Microsoft Shared\Web Server Extensions\12\Bin

When you are in the Admin groups, you will able to use this command and perform all the functions.
Site Backup & Site Restore:
Navigate to the following path in command prompt first
C:\>cd Program Files\Common Files\Microsoft Shared\web server extensions\12\bin

1. C:\ Program Files\Common Files\Microsoft Shared\web server extensions\12\bin>stsadm.exe –o backup –url “Site URL” –filename “Location of DAT file with extension” -overwrite
2. C:\ Program Files\Common Files\Microsoft Shared\web server extensions\12\bin>stsadm.exe –o restore –url “Site URL” –filename “Location of DAT file with extension” –overwrite

Example:
Location of DAT file with extension – D:\FolderName\FileBackup.dat