Scenario:
Already I am a big fan of Powershell. I thought of setting my solution using Power shell on a new machine.Script just worked great.
Let me share few of the them which we all use often.
Code:
###########################################################################################
# Create a new WebApplication
###########################################################################################
$newWebApplicationUrl = "http://intranet.contoso.com" $ApplicationPoolAccount = Get-SPManagedAccount "contoso\Administrator" New-SPWebApplication -Name "CustomApplication" -ApplicationPool "CustomApplication-80" -ApplicationPoolAccount $ApplicationPoolAccount -Port 80 –Url $newWebApplicationUrl###########################################################################################
#Enabled Claim Based authentication for Existing Web Application:
###########################################################################################
$webApplicationUrl = "http://intranet.contoso.com" $webapp= Get-SPWebApplication $webApplicationUrl $webapp.UseClaimsAuthentication $webapp.UseClaimsAuthentication=$True $webapp.Update() $webapp.ProvisionGlobally() iisreset###########################################################################################
# Add new managed path for Projects Site Collections:
###########################################################################################
$webApplicationUrl = "http://intranet.contoso.com" New-SPManagedPath –RelativeURL "/ProjectCentral" -WebApplication $webApplicationUrl -Explicit New-SPManagedPath –RelativeURL "/Projects" -WebApplication $webApplicationUrl###########################################################################################
# To add/deploy custom solutions in central administration.
###########################################################################################
Add-SPSolution -LiteralPath CustomApplication.wsp Install-SPSolution -Identity CustomApplication.wsp –AllWebApplications –GACDeployment###########################################################################################
# To create a site collection:
###########################################################################################
$projectCentralUrl = "http://intranet.contoso.com" $siteTitle="Project Central"; $owner="contoso\administrator" $template=”STS#0” $newSiteColl = New-SPSite $projectCentralUrl –Name $siteTitle –OwnerAlias $owner –Template $template $newSiteColl.Dispose()###########################################################################################
# Enable publishing infrastructure features
###########################################################################################
Enable-SPFeature -Identity PublishingSite -url $projectCentralUrl Enable-SPFeature -Identity PublishingWeb -url $projectCentralUrl###########################################################################################
# Enable Performance Point feature at Site Collection level
###########################################################################################
Enable-SPFeature -Identity PPSSiteCollectionMaster -url $projectCentralUrl###############################################################################################
# To create a subsite for TeamManagement under Project Central with unique permissions:
###############################################################################################
$webTeamManagement = New-SPWeb –Name "Team Management" –Url "$projectCentralUrl/TeamManagement" -Template "STS#1" –UniquePermissions #Owners group creation ( Assuming Client Authentication Enabled ) $owner = $webTeamManagement.AllUsers["i:0#.w|contoso\administrator"] $ownerGroupName ="$webTeamManagement Owners" $webTeamManagement.SiteGroups.Add($ownerGroupName,$owner,$owner,$ownerGroupName) $ownerGrp = $webTeamManagement.SiteGroups[$ownerGroupName] $webTeamManagement.AssociatedOwnerGroup = $ownerGrp $ownerRole="Full Control" $ownerAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($ownerGrp) $ownerRoleDefinition=$webTeamManagement.RoleDefinitions[$ownerRole] $ownerAssignment.RoleDefinitionBindings.Add($ownerRoleDefinition) $webTeamManagement.RoleAssignments.Add($ownerAssignment); #Members group creation ( Assuming Client Authentication Enabled ) $member = $webTeamManagement.AllUsers["i:0#.w|contoso\administrator"] $memberGroupName ="$webTeamManagement Members" $webTeamManagement.SiteGroups.Add($memberGroupName,$member,$member,$memberGroupName) $memberGrp = $webTeamManagement.SiteGroups[$memberGroupName] $webTeamManagement.AssociatedMemberGroup = $memberGrp $memberRole="Contribute" $memberAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($memberGrp) $memberRoleDefinition=$webTeamManagement.RoleDefinitions[$memberRole] $memberAssignment.RoleDefinitionBindings.Add($memberRoleDefinition) $webTeamManagement.RoleAssignments.Add($memberAssignment); #Visitors group creation ( Assuming Client Authentication Enabled ) $visitor = $webTeamManagement.AllUsers["i:0#.w|contoso\administrator"] $visitorGroupName ="$webTeamManagement Visitors" $webTeamManagement.SiteGroups.Add($visitorGroupName,$visitor,$visitor,$visitorGroupName) $visitorGrp = $webTeamManagement.SiteGroups[$visitorGroupName] $webTeamManagement.AssociatedVisitorGroup = $visitorGrp $visitorRole="Read" $visitorAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($visitorGrp) $visitorRoleDefinition=$webTeamManagement.RoleDefinitions[$visitorRole] $visitorAssignment.RoleDefinitionBindings.Add($visitorRoleDefinition) $webTeamManagement.RoleAssignments.Add($visitorAssignment); $webTeamManagement.Update() $webTeamManagement.Dispose()####################################################################################################
# To create a subsite for Report Center under Project Management with unique permissions:
####################################################################################################
$webReportCenter = New-SPWeb –Name "Report Center" –Url "$projectCentralUrl/BI" -Template "BICENTERSITE#0" –UniquePermissions #Owners group creation $owner = $webReportCenter.AllUsers["i:0#.w|contoso\administrator"] $ownerGroupName ="$webReportCenter Owners" $webReportCenter.SiteGroups.Add($ownerGroupName,$owner,$owner,$ownerGroupName) $ownerGrp = $webReportCenter.SiteGroups[$ownerGroupName] $webReportCenter.AssociatedOwnerGroup = $ownerGrp $ownerRole="Full Control" $ownerAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($ownerGrp) $ownerRoleDefinition=$webReportCenter.RoleDefinitions[$ownerRole] $ownerAssignment.RoleDefinitionBindings.Add($ownerRoleDefinition) $webReportCenter.RoleAssignments.Add($ownerAssignment); #Members group creation $member = $webReportCenter.AllUsers["i:0#.w|contoso\administrator"] $memberGroupName ="$webReportCenter Members" $webReportCenter.SiteGroups.Add($memberGroupName,$member,$member,$memberGroupName) $memberGrp = $webReportCenter.SiteGroups[$memberGroupName] $webReportCenter.AssociatedMemberGroup = $memberGrp $memberRole="Contribute" $memberAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($memberGrp) $memberRoleDefinition=$webReportCenter.RoleDefinitions[$memberRole] $memberAssignment.RoleDefinitionBindings.Add($memberRoleDefinition) $webReportCenter.RoleAssignments.Add($memberAssignment); #Visitors group creation $visitor = $webReportCenter.AllUsers["i:0#.w|contoso\administrator"] $visitorGroupName ="$webReportCenter Visitors" $webReportCenter.SiteGroups.Add($visitorGroupName,$visitor,$visitor,$visitorGroupName) $visitorGrp = $webReportCenter.SiteGroups[$visitorGroupName] $webReportCenter.AssociatedVisitorGroup = $visitorGrp $visitorRole="Read" $visitorAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($visitorGrp) $visitorRoleDefinition=$webReportCenter.RoleDefinitions[$visitorRole] $visitorAssignment.RoleDefinitionBindings.Add($visitorRoleDefinition) $webReportCenter.RoleAssignments.Add($visitorAssignment); $webReportCenter.Update() $webReportCenter.Dispose()####################################################################################################
# To create FAST Search Center needs to activate Sharepoint Server Public Infrastructure feature:
####################################################################################################
$webSearch = New-SPWeb –Name "Search" -Url "$projectCentralUrl/Search" -Template "SRCHCENTERFAST#0" $webSearch.Dispose()####################################################################################################
# Activate Site Collection Features & Site Features of My Workspace:
####################################################################################################
Enable-SPFeature -Identity "CustomSolution_XSLTFiles" –Url $projectCentralUrl Enable-SPFeature -Identity "CustomSolution_SavedSearchesListInstance" –Url $projectCentralUrl Enable-SPFeature -Identity "CustomApplication_TeamManagementSiteFeature" –Url $projectCentralUrl Enable-SPFeature -Identity "ProjectXSNForms" –Url $projectCentralUrl####################################################################################################
# Activate Features on Project Management:
####################################################################################################
Enable-SPFeature -Identity "CustomSolution_FeatureX" –Url "$projectCentralUrl/TeamManagement"####################################################################################################
# Get new web objects for all the webs
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" $webProjectCentral = Get-SPWeb "$projectCentralUrl" $webTeamManagement = Get-SPWeb "$projectCentralUrl/TeamManagement" $webReportCenter = Get-SPWeb "$projectCentralUrl/bi" $webSearch = Get-SPWeb "$projectCentralUrl/search"####################################################################################################
# Adjusting the master page from OOTB to CustomApplication based master pages
####################################################################################################
$webTeamManagement.Navigation.UseShared = $true $pubWebProjectCentral = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($webprojectCentral) $pubWebProjectCentral.IncludeSubsitesinNavigation=$True $pubWebProjectCentral.CustomMasterUrl.SetValue($pubWebProjectCentral .CustomMasterUrl.Value.Replace("v4","Custom")) $pubWebProjectCentral.MasterUrl.SetValue($pubWebProjectCentral .MasterUrl.Value.Replace("v4","Custom")) $pubWebSearch = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($webSearch) $pubWebSearch.CustomMasterUrl.SetValue($pubWebSearch.CustomMasterUrl.Value.Replace("minimal","CustomApplication_minimal"))############################################################################################
# Adjusting the search center url
###########################################################################################
$searchUrl="/Search/Pages" $webProjectCentral.AllProperties["SRCH_ENH_FTR_URL"] = $searchUrl $webProjectCentral.AllProperties["SRCH_SITE_DROPDOWN_MODE"] = "ShowDD"############################################################################################
# Update Web objects and dispose them
###########################################################################################
$pubWebProjectCentral.Update() $pubWebSearch.Update() $webProjectCentral Update() $webTeamManagement.Update() $webReportCenter.Update() $webSearch.Update() $webSearch.Dispose() $webReportCenter.Dispose() $webTeamManagement.Dispose() $webProjectCentral.Dispose()####################################################################################################
# To associate workflow to list
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" $web = Get-SPWeb "$projectCentralUrl/TeamManagement" $list = $web.Lists.TryGetList("Project Forms") $workflowInstanceName = "Project Site Status" $workflowName = "CustomApplication-New Project Site Collection WF" $historylistguid =$web.Lists.Add("Project Workflow History","",140) $historylist =$web.Lists[$historylistguid] $tasklistguid =$web.Lists.Add("Project Workflow Tasks","",107) $tasklist=$web.Lists[$tasklistguid] $culture=new-object System.Globalization.CultureInfo("en-US") $basetemplate = $web.WorkflowTemplates.GetTemplateByName($workflowName,$culture) $workflowAssociation=[Microsoft.SharePoint.Workflow.SPWorkflowAssociation]::CreateListAssociation($basetemplate,$workflowInstanceName ,$taskList,$historyList) $workflowAssociation.AutoStartCreate = $True; $list.WorkflowAssociations.Add($workflowAssociation) $list.Update(); $web.Dispose()####################################################################################################
# Create a new site collection
####################################################################################################
$ProjectSeriesID = "00001" $newSiteCollectionUrl = "http://intranet.contoso.com/Projects/$ProjectSeriesID" $owner="contoso\administrator" $template=Get-SPWebTemplate "CustomApplicationSiteDefinition#0" $siteTitle=$ProjectSeriesID $newProjectSiteCollection = New-SPSite -URL $newSiteCollectionUrl -Name $siteTitle -OwnerAlias $owner -Template $template $newProjectSiteCollection.Dispose()####################################################################################################
# Adding a new link to Link List
####################################################################################################
$siteCollectionUrlForSitePool = "http://intranet.contoso.com" $sitecoll=Get-SPSite $siteCollectionUrlForSitePool; $webTeamManagement= Get-SPWeb "http://intranet.contoso.com/TeamManagement" $List=$webTeamManagement.Lists["My Links"]; $item=$List.Items.Add() $item["Title"]="Project Site" $item["Site Url"]="http://intranet.contoso.com/Projects/00001" $item.update() $List.update() $webTeamManagement.Dispose()####################################################################################################
# This will switch the home page for TeamManagement with a tabbed UI
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" $webProjectCentral = Get-SPWeb "$projectCentralUrl/TeamManagement" $sfile = $webProjectCentral.GetFile("default.aspx") $dfile = $webProjectCentral.GetFile("home.aspx") $dfile.CheckOut() $dfile.SaveBinary($sfile.OpenBinary()) $dfile.CheckIn("done using code") $webProjectCentral.Update()####################################################################################################
#Remove Team Management Sub Site
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" Remove-SPWeb "$projectCentralUrl/CaseManagement"####################################################################################################
# Remove Site Collection
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" Remove-SPSite -Identity $projectCentralUrl -GradualDelete -Confirm:$False####################################################################################################
#Remove WebApplication with content databases and IIS
####################################################################################################
$projectCentralUrl = "http://intranet.contoso.com" Remove-SPWebApplication $projectCentralUrl -Confirm -DeleteIISSite -RemoveContentDatabases####################################################################################################
# Retracting and Removing CustomApplication Solution
###################################################################################################
$solutionPackageName = "CustomApplication.wsp" $solution = Get-SPSolution | where-object {$_.Name -eq $solutionPackageName} # check to see if solution package has been installed if ($solution -ne $null) { if($solution.Deployed -eq $true) { Uninstall-SPSolution -Identity $solutionPackageName -AllWebApplications -Local -Confirm:$False } } Remove-SPSolution -Identity $solutionPackageName -Confirm:$falseArticle:
Search center options , Some more commands
0 comments:
Post a Comment