Search SharePoint 2010 – Simple Steps to follow

Step I >> Goto central Admin> Application Management >Manage Service Application

Image

Step 2>> Search Service Application

Image

Step 3>> Metadeta Propertie – Choose from left navigation menu

Image

Step 4>> Create “New Managed Property”

Image

Step 5>> Add Mapping

Image

Step 6>> Allow property to be used in scope

Image

Step 7>> Content Source

Image

Step 8>> File Type – can do Settings of Files Type

Image

Step 9>> Scope – can be set scope

SharePoint PowerShell in details with examples

Introduction

  • This is Command line scripting tool
  • Design based on .Net Framework
  • Does have support object oriented concept and special libraries as we use in .net
  • Helping tool for Automate SharePoint 2010 Administrator tasks
  • Replacement for STSADM command shell
  • Debugging can be done in PowerShell ISE
  • Current version used PowerShell V2 or 2.0

Environmental Requirements

  • Dotnet framework should be installed (As we have SFS and SPS already installed, not to worry J)
  • User must be a member of SharePoint_Shell_Access role or WSS_Admin_WPG local group
  • PS script should executed on Server
  • Powershell scripts can be executed remotely from local machine by enabling remote support on SharePoint server.

Enable –PSRemoting

Enable-WSmanCredSSP

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000

  • Signing of scripts to avoid restrictions while running.

Special Features of PowerShell

  • Cmdlets – Executable units verb-noun
  • Windows PowerShell also gives you access to the file system
  • Scripts – file with powershell commands and/or Cmdlets with extension of .ps1
  • To run script  >> .\powershellname.ps1
  • Parameterized calling of .ps1 file – default parameter values can be set. Custom parameters
  • One .ps1 file can call another .ps1 file
  • Intellisence, Color coding, debugging can be possible (using tool – PowerShell ISE)
  • Pipelining operator (|), one cmdlet can pass object to second through pipelining (Cmdlet1 | Cmdlet2)
  • Provider based model – bunch of Cmdlets provided with the installation of PowerShell
  • Set-executionPolicy bypass
  • Notepad, PowerShell ISE (Integrated Scripting Environment) in V2 inbuilt in Windows server 2008 R2 – enable in windows server explorer
  • Load SharePoint Snap-in, no need to do load in case of ‘Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell’ opened as Administrator.
  • Regular.Net coding against object model
  • Powershell scripts can be executed from powershell command prompt and Powershell ISE (F5).
  • While using Windows PowerShell console ‘Add –PSSnapin Microsoft.SharePoint.PowerShell’ in the SharePoint.ps1 file located in%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration

Use PowerShell over STSADM

  • Windows PowerShell also gives you access to the file system
  • As PowerShell designed based on .net framework it does support object oriented concept and special libraries as we use in .net
  • Scripts – file with powershell commands and/or Cmdlets with extension of .ps1

Examples of PowerShell Programming

  • Parameter passing

  • How to call Parameterised .ps1 file

  • Where clause
  • $
  • | operator
  • Feareach loop
  • Array List
  • create new site collections, Web applications, user accounts, service applications,
  • proxiesmanipulate sites, lists, document libraries
  • Setting master page
  • Installing, activating features
  • Enabling developer dashboard
  • References : http://technet.microsoft.com/en-us/library/ee221100.aspx

Full Code Examples 

param(
[string] $envType = $(throw “envType(PersonalDev, Test or Production)required”),
[string] $workFolder = (Get-Item (“.”)).FullName,
[string] $createFullHierarchy =”True”,
[string] $recreateWebApplication =”False”,
[string] $createVariations =”False”,
[string] $recreateMySiteHost=”False”,
[string] $recreateTermStore=”False”,
[string] $activateFarmFeature=”False”
)

# This is to ensure SharePoint Snapin’s are loaded in PowerShell
if(-not(Get-PSSnapin | Where { $_.Name -eq “Microsoft.SharePoint.PowerShell”})) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

#
# Set global variables used for all environments
#
$solName = “Team.RMS.wsp”
$metadataService =””
$deploySleepSecs = 35
#####$rootTempl = “BLANKINTERNET#0”
$rootTempl = “{95551a43-4583-4d97-88d5-56d6c9c292b4}#WTRoot”
$rootTitle = “Home”
#####$ResTrackTempl = “{95551a43-4583-4d97-88d5-56d6c9c292b4}#WTResourceTrack”
$ResTrackTempl = “STS#0”
$ResTrackTitle = “Resource Tracking”
$ResTrackUrl = “rt”

$ResTrackTempl1 = “STS#0”
$ResTrackTitle1 = “Resource Tracking Test”
$ResTrackUrl1 = “rt1”

switch ($envType)
{
“PersonalDev”
{
$farmAccount = “<Domain>\<UserName_Admin>”
$comp = Get-WmiObject -Class Win32_ComputerSystem
$centralAdminUrl = “http://&#8221; + $comp.Name + “:21633”
$hostHeader = “intra.RMS.local”
$port = 80
$siteUrl = “http://&#8221; + $hostHeader
$appPoolName = “SharePoint – ” + $hostHeader + $port
$solPath = (Get-ChildItem (“..\bin\Debug\” + $solName)).FullName
$ownerAccount = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$logFile = $workFolder + “\ReinstallPersonalDev.log”
$appName = “RMS Intranet”
$appPoolAccount = “<Domain>\<UserName_Admin>”
$databaseName = “RMS_Content_” + $comp.Name
$databaseServer = “<ServerName>\SharePoint”
$mySiteHostHeader=”mysites.RMS.local”
$mySiteUrl=”http://”+$mySiteHostHeader
$mysiteAppPoolName = “SharePoint – ” + $mySiteHostHeader + $port
$mySiteAppName = “RMS My Site”
$mySiteDatabaseName = “RMSMySite_Content_” + $comp.Name
$metadataService = “Managed Metadata Service”
$userProfSerApp = “User Profile Service Application”
$SiteCollectionAdminArray = @(
@(“<Domain>\<UserName_Admin>”),
@(“<Domain>\<UserName_Admin2>”),
@($comp.Name + “\RMSUser1”)
)
$userArray = @(
@($comp.Name + “\RMSUser2”, 1),
@($comp.Name + “\RMSUser3”, 2),
@($comp.Name + “\RMSUser4”, 3)
)
}

“Test”
{
####TODO
}
“Production”
{
####TODO
}
default
{
throw “Error: unknown value given for parameter 1 envType”
}
}

#
# Functions
#
function LogProgress($message)
{
$now = Get-Date –f “yyyy-MM-dd HH:mm:ss”
Write-Host `n $now.ToString() -: $message
}

[HashTable] $htSPUserGroup=@{
1 = “Home Owners”;
2 =”Home Members”;
3 =”Home Visitors”;
}

function AddUsersSiteCollectionAdmin($SiteCollectionAdminArray)
{
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName=$user
New-SPUser -UserAlias $UserName -Web $siteUrl -SiteCollectionAdmin
}
}

function AddUsers($userArray)
{
foreach ($user in $userArray)
{
[array] $UserSplit=$user[0].split()
[string] $UserName=$UserSplit[0].trim()
[int] $GroupID=$UserSplit[1].trim()
[string] $GroupName=$htSPUserGroup[$GroupID].trim()
New-SPUser -UserAlias $UserName -Web $siteUrl -Group $GroupName
}

}

#
# Start work
#
Start-Transcript -Path $logFile -Append:$false
LogProgress “Starting reinstall”
iisreset

LogProgress “Adding user profile service application administrators”

$spapp = Get-SPServiceApplication -Name $userProfSerApp
$spguid = $spapp.id
$security = Get-SPServiceApplicationSecurity $spguid -Admin
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName = $user
$principalUser = New-SPClaimsPrincipal -Identity $UserName -IdentityType WindowsSamAccountName
Grant-SPObjectSecurity $security -Principal $principalUser -Rights “Full Control”
}
Set-SPServiceApplicationSecurity $spapp $security –Admin
(Get-SPServiceApplicationSecurity $spapp -Admin).AccessRules
LogProgress “Adding user profile service invocation permissions”

$farmid = Get-SPFarm | select id
$claimProvider = (Get-SPClaimProvider System).ClaimProvider
$spapp = Get-SPServiceApplication -Name $userProfSerApp
$spguid = $spapp.id
$security = Get-SPServiceApplicationSecurity $spguid
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName = $user
$principalUser = New-SPClaimsPrincipal -Identity $UserName -IdentityType WindowsSamAccountName
Grant-SPObjectSecurity $security $principalUser -Rights “Full Control”
}
Set-SPServiceApplicationSecurity $spguid -ObjectSecurity $security
(Get-SPServiceApplicationSecurity $spguid).AccessRules
LogProgress “Adding managed metadata service application administrators”

$spapp = Get-SPServiceApplication -Name $metadataService
$spguid = $spapp.id
$security = Get-SPServiceApplicationSecurity $spguid -Admin
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName = $user
$principalUser = New-SPClaimsPrincipal -Identity $UserName -IdentityType WindowsSamAccountName
Grant-SPObjectSecurity $security -Principal $principalUser -Rights “Full Control”
}
Set-SPServiceApplicationSecurity $spapp $security –Admin
(Get-SPServiceApplicationSecurity $spapp -Admin).AccessRules

LogProgress “Adding managed metadata service invocation permissions”

$farmid = Get-SPFarm | select id
$claimProvider = (Get-SPClaimProvider System).ClaimProvider
$spapp = Get-SPServiceApplication -Name $metadataService
$spguid = $spapp.id
$security = Get-SPServiceApplicationSecurity $spguid
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName = $user
$principalUser = New-SPClaimsPrincipal -Identity $UserName -IdentityType WindowsSamAccountName
Grant-SPObjectSecurity $security $principalUser -Rights “Full Access to Term Store”
}
Set-SPServiceApplicationSecurity $spguid -ObjectSecurity $security
(Get-SPServiceApplicationSecurity $spguid).AccessRules

if($recreateTermStore -eq “True”)
{
LogProgress “Adding term store administrators”

$taxonomySite = Get-SPSite $centralAdminUrl
#Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$termStore = $taxonomySession.TermStores[$metadataService]
foreach ($user in $SiteCollectionAdminArray)
{
[string] $UserName = $user
$termStore.AddTermStoreAdministrator($UserName)
}
#Update the Term Store
$termStore.CommitAll()
$taxonomySite.Dispose()
}

LogProgress “Deleting site collection”
$targetsiteurl = Get-SPSite $siteUrl
if ($targetsiteurl)
{
LogProgress “Site collection found, deleting”
Remove-SPSite -Identity $siteUrl -Confirm:$false
}
else
{
LogProgress “Skipping deletion, site collection does not exist”
}
if($recreateWebApplication -eq “True”)
{
LogProgress “Deleting web application”
$targetUrl = Get-SPWebApplication $siteUrl
if ($targetUrl)
{
LogProgress “Web application found, deleting”
Remove-SPWebApplication -Identity $siteUrl -DeleteIISSite:$true -RemoveContentDatabases:$true -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}
else
{
LogProgress “Skipping deletion, web application does not exist”
}
}

LogProgress “Uninstalling solution”
$SolutionTocheck = Get-SPSolution -identity $solName -ErrorAction:SilentlyContinue
if ($SolutionToCheck)
{
if ($SolutionToCheck.Deployed)
{
LogProgress “Solution found, uninstalling”
Uninstall-SPSolution -Identity $solName -WebApplication $siteUrl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}
else
{
LogProgress “Skipping uninstall, solution does not exist”
}
}

LogProgress “Removing solution”
$SolutionTocheck = Get-SPSolution -identity $solName -ErrorAction:SilentlyContinue
if ($SolutionToCheck)
{
LogProgress “Solution found, removing”
Remove-SPSolution -Identity $solName -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}
else
{
LogProgress “Skipping removal, solution does not exist”
}

iisreset

if($recreateWebApplication -eq “True”)
{
LogProgress “Creating web application”
New-SPWebApplication -Name $appName -Port $port -HostHeader $hostHeader -URL $siteUrl -ApplicationPool $appPoolName -ApplicationPoolAccount (Get-SPManagedAccount $appPoolAccount) -DatabaseName $databaseName -DatabaseServer $databaseServer -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}

if($recreateMySiteHost -eq “True”)
{
LogProgress “Deleting My Site web application”
Remove-SPWebApplication -Identity $mySiteUrl -DeleteIISSite:$true -RemoveContentDatabases:$true -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Creating My Site web application”
New-SPWebApplication -Name $mySiteAppName -Port $port -HostHeader $mySiteHostHeader -URL $mySiteUrl -ApplicationPool $mysiteAppPoolName -ApplicationPoolAccount (Get-SPManagedAccount $appPoolAccount) -DatabaseName $mySiteDatabaseName -DatabaseServer $databaseServer -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Creating My Site collection”
New-SPSite -Url $mySiteUrl -OwnerAlias $ownerAccount -Name $mySiteRootTitle -Template $mySiteTempl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Enable Self-Service Site Creation”
Set-Alias -Name stsadm -Value $env:CommonProgramFiles”\Microsoft Shared\Web Server Extensions\14\BIN\STSADM.EXE”
stsadm -o enablessc -url $mySiteUrl
Start-Sleep -Seconds $deploySleepSecs

LogProgress “My Site Host url for User Profile Service Application”
$userProf = Get-SPServiceApplication -Name $userProfSerApp
$userProfGuid = $userProf.id
Set-SPProfileServiceApplication -Identity $userProfGuid -MySiteHostLocation $mySiteUrl
Start-Sleep -Seconds $deploySleepSecs
}

LogProgress “Adding solutions”
Add-SPSolution -LiteralPath $solPath -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Installing solutions”
Install-SPSolution -Identity $solName -GACDeployment -Confirm:$False -force
Start-Sleep -Seconds $deploySleepSecs

iisreset
#To Execute Admin Timer jobs – Equivalent to STSADM -o execadmsvcjobs
net stop SPAdminV4
Start-SPAdminJob
net start SPAdminV4

if($activateFarmFeature -eq “True”)
{

LogProgress “Activating farm-scoped features”

LogProgress “Activating logging config, which must be first web app feature activated”
Enable-SPFeature -Identity No talent party this year
http://intra2.Team.com/News/News-folder/Corporate-News/Christmas–Year-End-celebrations

.Team.Intra_LoggingConfig -Url $siteUrl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Activating debugging feature”
Enable-SPFeature -Identity Team.Intra_DebugConfig -Url $siteUrl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs

LogProgress “Activating web config mods feature”
Enable-SPFeature -Identity Team.Intra_WebConfigMods -Url $siteUrl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}
LogProgress “Creating site collection”
New-SPSite -Url $siteUrl -OwnerAlias $ownerAccount -Name $rootTitle -Template $rootTempl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
if($activateFarmFeature -eq “True”)
{
LogProgress “Activating TaxonomyFieldAdded feature (done here because does not work in onet.xml)”
Enable-SPFeature -Identity TaxonomyFieldAdded -Url $siteUrl -Confirm:$false
Start-Sleep -Seconds $deploySleepSecs
}

iisreset

LogProgress “Creating first-level sites”
New-SPWeb -Url ($siteUrl + “/” + $ResTrackUrl) -Name $ResTrackTitle -Template $ResTrackTempl

Start-Sleep -Seconds $deploySleepSecs

if($createFullHierarchy -eq “True”)
{
LogProgress “Creating second-level sites”
##todo
}

if($createVariations -eq “True”)
{
##todo
}

if($recreateMySiteHost -eq “True”)
{
LogProgress “Activating My Site Master Pages feature-For My site”
Enable-SPFeature -Identity Team.Intra_MUIEnabler -Url $mySiteUrl -Confirm:$false
Enable-SPFeature -Identity Team.Intra_MySiteUI -Url $mySiteUrl -Confirm:$false

LogProgress “Updating My Site Master Page”
.\UpdateMySiteMasterPage -mySiteUrl $mySiteUrl
}

LogProgress “Adding site users”
AddUsers($userArray)

LogProgress “Adding site collection administrators”
AddUsersSiteCollectionAdmin($SiteCollectionAdminArray)

LogProgress “Done!”

Stop-Transcript