Monday, December 14, 2015

Restore SharePoint WebApplication from a different Farm

Hi Again! Long time, huh..
Every time I try to get a backup from SharePoint Farm and restore it to different farm I face a lot of problems, mainly in getting backup from SharePoint.. so better to get a Database backup.. but how to restore it in the other Farm!! ,, Perform the below steps then check the PowerShell script:

1- Back–up content database from the Source SP SQL server and restore it in Destination SP SQL Server.
2- Make Sure that the new Content DB has correct permissions (read & write).

#PowerShell Code start
Add-PSSnapin Microsoft.SharePoint.PowerShell

#Define your parameters
$DBServer= "SQLServer\SP"
$oldContentDB= "Old_ContentDB"

#Check the compatibility of the web application with the restored content database
Test-SPContentDatabase -Name $newContentDB -WebApplication $webAppName

#UnMount old content database from the web Application
Dismount-SPContentDatabase $oldContentDB

#Mount the restored content database and attach it to the web Application
Mount-SPContentDatabase $newContentDB -DatabaseServer $DBServer -WebApplication $webAppName


Tuesday, September 2, 2014

Configure People Picker Settings in SharePoint 2013

The Problem isIf a web application is using Windows authentication and the site user directory path is not set, the People Picker control searches all the Active Directory to resolve users' names or find users, instead of searching only users in a particular organizational unit (OU).” Microsoft TechNet site said.

Below is the PowerShell and stsadm commands to Retrieve Users from a Specific OU in Active Directory:

Get current user account directory path for all Site Collections in a Web Application:
Get-SPSite -Limit All | Select Url, UserAccountDirectoryPath 

Get current service account directory path:
stsadm -o getproperty -url http://ServerName -pn peoplepicker-serviceaccountdirectorypaths 

Set service account directory path:
stsadm -o setproperty -url http://contosto -pn "peoplepicker-serviceaccountdirectorypaths" -pv "OU=Contoso-Admin,DC=Contoso,DC=com" 

Configure settings for Web Application (All Site Collections in  a Web Application):
$WebApp = "http://WebApp"
Get-SPWebApplication $WebApp | Get-SPSite -Limit All |ForEach-Object { Set-SPSite -Identity $_.Url -UserAccountDirectoryPath "OU=Contoso-Users,DC=Contoso,DC=com" }

Configure settings for a Site Collection:
Set-SPSite -Identity "http://Contoso/SiteCollection" -UserAccountDirectoryPath "OU=Contoso-Users,DC=Contoso,DC=com"

Monday, June 9, 2014

Configuring OneDrive for Business Use in SharePoint 2013

       1- Blocking File Types:
a. Central Administration > Manage Web Applications > The MySite Web Application > “Blocked File Types” from the ribbon.
b. Add the extension you want in a new line.

              2- Quota Limit Per User:
a. Create Personal Quota template.
b. Change Quota template for the Site Collection of the user
Central Admin > Application Management > Site Collections > Configure quotas and locks, or if you have large number of sites then use this PowerShell;

$SPWebApp = Get-SPWebApplication http://MySite

foreach ($SPSite in $SPWebApp.Sites)
    if ($SPSite -ne $null)
        Set-SPSite -Identity $SPSite.url -QuotaTemplate "Quota Template Name"

             3- Set max upload size:
a. Central Admin > Manage Web Applications > The MySite Web Application > “General Settings” from the ribbon.
b. In the “Maximum upload size”, add the size.

Wednesday, June 4, 2014

Get SharePoint 2013 Site Collection Size Using PowerShell

I was trying to get the usage size for one of the SharePoint personal sites, and I ended up with this script.
The script is for getting all site collections usage compared to its maximum size, sorted by size of the Site Collections and the output to a HTML file.

$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 1px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 1px;border-style: solid;border-color: black;}"
$a = $a + "</style>"

Get-SPSite -Limit All | select url, @{label="Size in MB";Expression={$}},@{label="Capacity";Expression={$_.Quota.StorageMaximumLevel/1MB}} | Sort-Object -Descending -Property "Size in MB" | ConvertTo-Html -Head $a -title "Site Collections sorted by size" | Set-Content sc.html


Sunday, May 25, 2014

Hide SharePoint Calculated Columns

Note that you can't hide the SharePoint calculated columns by the normal way, you have to use PowerShell to do that !

$web = get-spweb http://SPWeb/Site/subsite $list = $web.Lists["list name"]
$field = $list.Fields["Column Name"] $field.ShowInDisplayForm = $false $field.ShowInEditForm = $false $field.ShowInListSettings = $false$field.ShowInVersionHistory = $false$field.ShowInViewForms = $false $field.ShowInNewForm = $false
$field.Update($true) $web.Site.Dispose()