Showing posts with label Powershell. Show all posts
Showing posts with label Powershell. Show all posts

Wednesday, 22 February 2017

SharePoint Online - Create Libraries automatically

A - OBJECTIVE: 

During data migration to move files from local drives to SharePoint Online, you may need to create a big number of libraries to anticipate the list (soft) threshold of 5,000 items.

B - PROBLEMS :

Creating libraries manually is tedious & a script to automate the process will be shared to ease your work.

C - SOLUTION:

Powershell script can be used at your own PC to create libraries automatically at any SharePoint Online site.

D - SOURCE CODE or BENCHMARK:

Pre-requisites:
  • SharePoint DLLs saved at your PC & loaded to the script session.
  • Source File which predefines all libraries in each row in the format of "Internal Name, External or Display Library Name".
  • SharePoint Online Management Shell must be installed at your PC.
What you need to do is:
  1. Load the neccessary components
  2. # Load DLLs
    Add-Type -Path "D:\SharePoint\PowerShell\SPO-DLL\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "D:\SharePoint\PowerShell\SPO-DLL\Microsoft.SharePoint.Client.Runtime.dll"
    Add-Type -Path "D:\SharePoint\PowerShell\SPO-DLL\Microsoft.SharePoint.Client.UserProfiles.dll"
     
    # Source File to be synced from SharePoint On-Prem to Online
    $sourcefile = "D:\Projects\Libraries.txt"
    
  3. Load your SharePoint tenant
  4. #variables that needs to be set before starting the script
    $siteURL = "https://anthonynhn.sharepoint.com/sites/fat/cs"
    $adminUrl = "https://anthonynhn-admin.sharepoint.com"
    $userName = "admin@anthonynhn.onmicrosoft.com"
    # Let the user fill in their password in the PowerShell window
    $password = Read-Host "Please enter the password for $($userName)" -AsSecureString
    
  5. Initialize the creation task
  6. # set SharePoint Online credentials
    $SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)  
    
    # Creating client context object
    $contextLocal = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
    $contextLocal.credentials = $SPOCredentials
    $contextLocal.ExecuteQuery() 
    
    $listTemplate = 101 #doclib
    
    Foreach ($line in [System.IO.File]::ReadLines($sourcefile)) {
        $lib = New-Object Microsoft.SharePoint.Client.ListCreationInformation
     $libInput = $line -split ',';
     
     # set the Internal Name
        $lib.Url = $libInput[0]
     
     # set the Lib Title
     $lib.title = $libInput[1]
     
        $lib.TemplateType = $listTemplate
        $list = $contextLocal.web.lists.add($lib)
        $contextLocal.load($list)
        #send the request containing all operations to the server
        try{
            $contextLocal.executeQuery()
            write-host "info: Created $($listTitle)" -foregroundcolor green
        }
        catch{
            write-host "info: $($_.Exception.Message)" -foregroundcolor red
        }  
    }
    

Thursday, 6 March 2014

Search Service Application

A - OBJECTIVE: to create a new Search Service Application.

B - PROBLEMS :

1. Search Application: Index Component grows bigger when more content is populated at SharePoint farm.

2. Available Drive Space: this should have at least twice the value of physical memory (RAM). By default, all Search components are saved at C drive and it will consume this drive; hence, it leads to many operational issues. For example: permissions removed silently due to the problem at Virtual memory swap file.

C - SOLUTION:

1. Search Availability: to ensure the Search service is available to users, "Query Processing" and "Index" components should be replicated at all SharePoint servers.


2. Index Components of Search Application should be allocated at a separate drive to cater for future growth & access speed.
# to move the Index Components at all SharePoint servers to drive I
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostWFE1 -RootDirectory "I:\FEOshareSearchComponents2015"
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostWFE2 -RootDirectory "I:\FEOshareSearchComponents2015"
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostApp -RootDirectory "I:\FEOshareSearchComponents2015"


D - SOURCE CODE:
### GET THE EXISTING ENVIRONMENT PARAMETERS ###
$ssa = Get-SPEnterpriseSearchServiceApplication "Search Service Application - FEOshare"
$current=Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$new=New-SPEnterpriseSearchTopology -Clone -SearchApplication $ssa -SearchTopology $current


# list all search servers deployed in the farm
$hostApp = Get-SPEnterpriseSearchServiceInstance -Identity "kc1mspappprd01"
$hostWFE1 = Get-SPEnterpriseSearchServiceInstance -Identity "kc1mspwfeprd01"
$hostWFE2 = Get-SPEnterpriseSearchServiceInstance -Identity "kc1mspwfeprd02"

# check the settings of the search application
Get-SPEnterpriseSearchStatus -SearchApplication "Search Service Application - FEOshare"


### RE-CONFIGURE TO ALLOCATE SEARCH COMPONENTS ###

# delete the old configuration at the default location (drive C)
$del = Get-SPEnterpriseSearchComponent -SearchTopology $new | ? {$_.Name -eq "IndexComponent1"}
Remove-SPEnterpriseSearchComponent -Identity $del -SearchTopology $new


# create new INDEX components at new location
# must configure RootDirectory https://technet.microsoft.com/en-us/library/jj219721.aspx
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostWFE1 -RootDirectory "L:\FEOshareSearch2015"
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostWFE2 -RootDirectory "L:\FEOshareSearchComponents2015"
New-SPEnterpriseSearchIndexComponent -SearchTopology $new -IndexPartition 0 -SearchServiceInstance $hostApp -RootDirectory "I:\FEOshareSearchComponents2015"


# create new QUERY PROCESSING component at new location
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $new -SearchServiceInstance $hostWFE1
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $new -SearchServiceInstance $hostWFE2

### SET THE NEW TOPOLOGY TO BE ACTIVE ###
Set-SPEnterpriseSearchTopology -Identity $new