Monday, February 1, 2021

Powershell script for cleaning Recycle bin

In this blog post we will learn, how we can clean the recycle bin with PowerShell script. This is another way of cleaning Recycle bin apart from UI.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

We will use the below script to clean up the items from the recycle bin.


$webApp=get-SPWebApplication "http://sharepointblog"
foreach ($SPSite in $webApp.Sites) {     #Here we are looping through all the web under site collection     foreach($SPWeb in $SPSite.AllWebs)     {         #Cleaning the 1st Stage of Recycle bin items        $SPWeb.RecycleBin.DeleteAll();         #Moving the all the items to 2nd stage level         $SPWeb.RecycleBin.MoveAllToSecondStage();     }     #Clean SharePoint site collection     $SPSite.RecycleBin.DeleteAll(); }

Tuesday, January 26, 2021

Powershell script for creating SharePoint Site/Subsite

In this post we will learn how to create SharePoint site/sub site using PowerShell scripts. Again it is not mandatory to create this in PowerShell but its another way of creating it. We can definitely create it using UI as well.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

Below is the syntax and example to create the site using PowerShell script.

New-SPWeb _URL<Here we need to replace it with site URL> -name <Name of the sub site> -template <Site template need to be used while creating>

Example:
New-SPWeb –Url "http://blogspot/SubSite" -Name "Subsite" -template STS#0

Sunday, January 24, 2021

PowerShell script for creating site collection in Sharepoint

In this blog post we will know how to create new site collection in sharepoint (this applies for 2010,2013, 2016, 2019) using power shell scripts. Again we can create site collection using UI as well but here we will use PowerShell.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

Below is the standard template we will use while creating the site collection, we can replace it with custom values as per the requirement.

New-SPSite –Url <URL of the site collection>
-Name <Site collection name>
-OwnerAlias <Site collection administrator>
-Template <In which template site needs to be created like blog, team etc>
Here we are creating team site collection with with SPAdmin as the owner.

New-SPSite "http://blogpost/sites/test" -OwnerAlias "blogpost\spadmin" -Language 1033 -Template STS#0

PowerShell script for creating web application in Sharepoint

In this blog post we will use PowerShell script for creating new web application in SharePoint. We can create web application from SharePoint central admin site as well, this is another way of creating the web application.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

Below is the script for creating the application, here 1st script refers to generic script where you can replace with your own value as per requirement.

New-SPWebApplication –ApplicationPool <Application pool name> -Name <Web app name> -ApplicationPoolAccount <service account for the application pool> -Port <port number>

Below is the sample script for creating web app by internal host header with sharepoint.blogspot.com and public url with http://www.blogspot.com 

New-SPWebApplication -Name "BlogSite" -Port 80 -HostHeader sharepoint.blogspot.com -URL "http://www.blogspot.com" -ApplicationPool "SharepointBlogspot" -ApplicationPoolAccount (Get-SPManagedAccount "blogspot\spadmin")

We can create web application with claim based authentication enabled for that we need to use below script.

$authprovider = New-SPAuthenticationProvider
New-SPWebApplication -Name "BlogSite" -Port 443 -URL "https://www.blogspot.com" -ApplicaitonPool "SharepointBlogSpot" -ApplicationPoolAccount (Get-SPManagedAccount "blogspot\spadmin") -AuthenticationProvider $authprovider -SecureScoketLayer

Thursday, January 21, 2021

Powershell scripts for getting Sharepoint System account

In this post we will try to get all the service account details in SharePoint environment. Before proceeding further in case if you are new to PowerShell make sure you visit this blog post to understand how to set up or how to start using PowerShell ISE.

There is cmdlet called SPProcessAccount which helps in getting all the required account details.

Local System account details

Get-SPProcessAccount –LocalSystem



LocalService account:

Get-SPProcessAccount –LocalService




NetworkService account:

Get-SPProcessAccount –NetworkService




Tuesday, January 19, 2021

SharePoint build version using PowerShell

In this blog post will discuss about how to get the Sharepoint build version from PowerShell script.

Before that there are many ways we can get the Sharepoint build version, this is one of the reliable way to get the build version.

We can get build version using SQL queries but as per MS recommendation we should avoid connecting to Sharepoint DB, in a way we can avoid using this

Another way is using file system, again its not reliable about the build version we can get which version of Sharepoint like is it 2010, 2013 or etc. Using the Microsoft.Sharepoint.dll version number located in respective folder we can get but there will be always chance the number will vary depending Service Pack or CU updates

Using Registry we can find the build number but again this is not reliable as CU update doesn't reflect the build number in Registry hence we can't use this.

Another reliable way is using Sharepoint central administration, from their we will get the version exact version of the Sharepoint product installed.

As scope of this post is PowerShell we will use PS to get the Sharepoint installed version.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
get-spfarm | select BuildVersion

Or simply we can use

(Get-SPFarm).BuildVersion



PowerShell script for changing the site logo

In this post we will go through the PowerShell script for updating or I can say changing the sharepoint site logo. Even though its pretty simple activity which we can perform it from UI, but using PS script will make us more comfortable once we used to it.

Note: Before going through the please go through my first post in power shell series which convers how to use PS scripts.

Below is the very simple script for updating the logo of the site.

$web = Get-SPWeb "http://sharepoint2013”
$web.SiteLogoUrl = "http://sharepoint2013/publishingimages/logo.png"
$web.SiteLogoDescription = "Sharepoint 2013 Logo"
$web.Update()



Monday, January 18, 2021

Change sharepoint site title and Description using Powershell

Here I am adding few PowerShell scripts in the upcoming blog post which all Sharepoint developer/admin will be using frequently. In each post I will add only code snippet in powershell so it will be easy to learn and remember Ashwell.

In this post I will provide the script to change the site title and description of the site.

Before that I want to make sure I am using Windows powershell ISE to run the script. We have option to run the script from VS code also.

Default location of PowerShell ISE will be available at the below location:

<%SystemRoot%>\System32\WindowsPowerShell\v1.0\PowerShell.exe

The discussion we are using here is meant for sharepoint 2013/16/19 not with Sharepoint Online(there is different way of using powershell for online and it will be discussed later)

As soon as we install sharepoint in the server, Powershell cmdlets available in the Management shell, here we dont need to install any other package to start working with this.

Note: All the required PS(Powershell) cmdlets will be available in Microsoft.SharePoint.PowerShell.dll

We can connect to sharepoint site, either using Sharepoint Management shell or Windows Powershell ISE(WPISE), if we are using WPISE then we need to register Microsoft.SharePoint.PowerShell.dll module for SharePoint Server cmdlets other wise we can skip this part.

Steps to add Snapin:

Add-PSSnapin Microsoft.SharePoint.PowerShell

Note: This needs to be added at the starting of the script, so that we wont get any error while executing the scripts:

Also there is another way we can register this as below(this is kind of good practice to follow)

$spSnapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.PowerShell'}
 if ($spSnapin -eq $null) {
Add-PSSnapin Microsoft.SharePoint.PowerShell }

In the above script we are making sure if the snapin is already available or not.

Who can run the script:

User who is running the script should have securityadmin role membership in SQL box also user should be part of Admin group.

How to open Sharepoint Management shell/Power ISE?

Its always good practice to open/run the shell with administration mode(run as admin)

Below is the script used to change the title and description of the site.

$Web= Get-SPWeb "http://sp2013"
$Web.Title = "Sharepoint 2013 Site"
$Web.Description = "Team site for Development"
$web.Update()



Tuesday, October 27, 2020

Add polls to Microsoft Teams meeting

In this article we will use Microsoft Teams meeting to insert poll before we close the team meetings.

Microsoft Teams alone is not sufficient to achieve this functionalities. We need Microsoft forms in order to achieve the same.

Using these 2 tools we can create Survey, Quizzes as well as Poll. MS teams doesn't have in built functionality to insert Poll. By using the below steps we can achieve this vert easily.

1) Open Microsoft Team and open calendar in the teams

2) Select any of the upcoming meeting where you want to insert the poll

3) Now join the meeting where poll needs to be inserted

4) Once we join the meeting minimize the meeting window and open new web browser and login to office.com. Now login into office.com with the same account which configured with Teams.

5) After successful login we will be landing into office.com user dash board as like below.

6) In the landing page if we are not able to see Microsoft Forms by default, click on All apps and this will take us to All Apps view.

Note: Step no 4,5,6 can be skipped by directly logging into forms.office.com

7) In that view we should be able to see Forms which can be used to create Quiz, Polls and surveys. 

8) On click of  MS forms will open forms page where we can see 2 option, create survey/quiz from blank form or we can chose existing template to create the quiz/survey. This is completely left to us how we want to set up the data.

9) In this article we will create form to chose the goodies for the team. Create new form and give the proper title for the form. Here what ever the options we need we can choose here it might be choice, long text, number etc.


10) Once all the questionaries' are ready click on Share button which is at the top most right corner of the page as shown below.


11) Now copy the URL and keep it handy which we need to use it in later part. There are various option available like QR code or even we can email the link. But for now we will just copy and keep it handy for further use in MS teams.


12) Now open the MS teams meeting and click on conversation and paste the URL which copied from the MS forms. Once we send the url the participant of the meeting can take the poll and fill the details.

Its always instant result we can seen in the responses.

The content published/images used are valid as on 27th October 2020, as MS will keep on updating the way we can create the polls.

Saturday, August 1, 2020

Ways to disable Sharepoint Online Modern Page Comments

In this article we will discuss about how to disable comments section in SharePoint Online Modern Page.

Most of the customers keep on asking SharePoint developer to make their page more interactive or kind of seeking opinion about the articles they published in the SharePoint intranet site.

This feature was not available out of the box in earlier version of SharePoint. To achieve this functionality, we need to build custom feature/component which most of the time causes page load issue or performance issue when it grows bigger.


So, Microsoft included this feature in the SharePoint modern page to add comments section to make it more interactive like below.





This is one part of the story and another part is many of customers they don’t want this feature enabled in the site as they are not sure about the what type of content will be published in the comments and it needs to be monitored by admin or we need to create approval workflow to make the content available to all users in the company, this will create some overhead to site admin.


In the next section we will see how we can disable the comments.

There are two ways we can disable the comments in the page
  1. Global Scope
  2. Page Scope

Global scope:


Disabling the page comments globally will affect the entire tenant. This includes all sites and all page library.
  1. Open SharePoint admin center
  2. Click Settings in SharePoint admin center
  3. Navigate to Comments section in the page, by default Comments will be enabled for all pages.
  4. Change the radio button as per the requirement (Disable to remove the comments from the page globally)

Note:

  • Changing this option will take minimum 15 minutes to reflect in the pages
  • Once global admin disables this option, then Site Owner or Site Member can’t enable back at the site collection level
  •  Disabling the comments history does not remove the comments added earlier. After enabling it back it will be show again.

The whole steps are depicted in the below picture.



Page scope:


  1. Click Edit button in the page
  2. Navigate to the bottom of the page where comments control/section is present
  3. Toggle the button to off position and automatically comments will be hidden
  4. Republish the page

Note:

  • Disabling the comments history does not remove the comments added earlier. After enabling it back it will be show again
  • Users with Contribute/Edit access can enable the comments in the page.

The whole steps are depicted in the below picture.















Based on the requirement we can enable/disable the comments at the page and global level.

The information provided in this post (images and steps) are taken on 1st August 2020.

Thursday, July 30, 2020

Remove Page Header in SharePoint online Pages

In this post we will discuss about how to remove the Page header from the SharePoint online pages.


Typically, most of us faced issues when we create new pages in the SharePoint online, there will be header with the title of the page will be shown as like below. Give the page name (Name your page section) and publish the page. I have given the page name as TestPage.




From SharePoint UI there is no way to hide the header at least till this article published, so to hide the Page Header we will use PowerShell commands to hide the content.

There are 2 ways we can achieve the hiding page header.

1) Page level - In this case we will focus only on hiding the page header for the specific page.
2) Site Level - In this approach we are disabling the Page header at the site level.

Now we will see how we can disable for specific page.

1) Open SharePoint management shell (Run as admin)
2) Run the below scripts to disable Page header


#Declare variables sunch as Page name, Site URL
$SiteUrl = "https://bangten.sharepoint.com"
$PageTitle = "TestPage"

#UseWebLogin Uses Default Browser Authentication incase 
#if we have not connected we can remove that
Connect-PnPOnline -Url $SiteUrl -UseWebLogin

#Here we are setting the Layout type to Home its kind of landing page
Set-PnPClientSidePage -Identity $PageTitle -LayoutType Home

#Later at any point of time if we want Page Header back then use the below script
#Set-PnPClientSidePage -Identity $PageTitle -LayoutType Article



















Note: The above script can be run from Windows Powershell ISE as well also I have provided script for revert it back to old variant.

Now we will see how we can disable at site level

1) Open sharepoint management shell(Run as Admin)
2) Run the below scripts to remove the page header 


#Declare variables sunch as Page name, Site URL
$SiteUrl = "https://bangten.sharepoint.com"

Connect-PnPOnline -Url $SiteUrl -UseWebLogin
$PageCollection = (Get-PnPListItem -List SitePages).FieldValues

#Here we will loop through site pages collection and set the layout
foreach($Page in $pageCollection){
    Set-PnPClientSidePage -Identity $Page.FileLeafRef -LayoutType Home

    #Using below line we can revert the changes
    #Set-PnPClientSidePage -Identity $Page.FileLeafRef -LayoutType Article
}


From above steps we came to how we can handle Page Header in the SharePoint Modern Pages.

Wednesday, July 29, 2020

SharePoint Hub Sites Overview

This is my first blog in SharePoint Online topic, Let's start with Hub Site which is major architecture change in terms of modern SharePoint site vs classic SharePoint sites.


 
Let’s start understanding the Hub site by going through its features

  • Hierarchical structure
This is one of the basic features of hub site, we will focus more on this section.
We do not have the concept of Sub sites in modern SharePoint anymore. In Classic SharePoint we have site collections and each site collections have several sub sites under it. All the site collections are maintained in a hierarchical structure. When customization grew more complicated and the user requirements became more agile, deleting sub sites and restructuring them is also more difficult.

Another main disadvantage is external sharing, external sharing is not possible to only one specific sub site, we need to enable external sharing for entire site collection. So, this will hamper the site security and maintenance.

As a gist, the hierarchical structure of site collections and their sub sites were not robust to the modern requirements.This problem can be overcome by using hub architecture where there is no concept hierarchical structure, it will be flat architecture. There are no sub sites. In modern SharePoint, every single site is a site collection. If we have any such requirement for hierarchical structure, then we can use hub site concept to achieve the same.

It is easily maintainable and restructure and external sharing can be done to any independent site collections present or associated to a hub site. So, the security and maintenance is like a piece of cake in this type of flat art hierarchy

  • Look and Feel
All Sub sites inherits their look and feel from the root (Hub site) which allows you to maintain a single branding across all your sites. In a simple term, all sites are associated, which means they resides under one Hub

  • Common/Shared Top Navigation (Global Navigation)
A common global navigation is maintained across all connected sites of the Hub site.
If we want to create custom navigation or we can call it as site specific navigation, we can still go ahead and create it

  • Scoped Enterprise Search
This is one of the very good feature of hub site. If we search for any content in the site it performs the search within all the sites of that Hub Site.

  • Content Aggregation
Automatically aggregates content and displaying from multiple sites. News Web Part, Sites Web Part and Content Web Part can be used in a Hub Site to aggregate content from the associated sites and display the content on the Hub Site’s home page. This reduces a lot of manual work that developers supposed to do to get this done in the earlier days.

Who can create SharePoint Hub Site?
SharePoint Administrator will be able to create SharePoint hub sites, however site owners can associate a SharePoint site with the hub site.


How we can create the hub sites?

For demo purpose I have created one communication (TestCommunication) and 2 team sites (TestHub, FinanceHub)

Let's start with opening Office 365 portal.



Now we will associate FinanceHub and TeamHub site to TestCommunication site.

Open TestCommunication site and go to the site settings and under the site information. We have an option called Hub Site Association. Right now, it is not associated to any hub site as below




The TestCommunication website which we created, was not a hub site yet. Until we do one final setting this we cannot use as hub site.


Now open SharePoint admin site, this opens SharePoint Admin Center (if this opens in classic mode, then open it in modern view)


Here we are performing the following steps:


1) Open SharePoint Admin Site (Change the site from classic mode to modern site)

2) Click on Active Sites, which will show the all the sites which we created in earlier section.





Now its time to make the site as Hub.


1) Select TestCommunication site and click Hub from the menu.

2) Select Register Site as Hub site

3) Give name of the Hub site and give the site owner name/give everyone access based on the business requirement. Careful while giving everyone permission.




In next step we will associate TeamHub site and Finance Hub site to Test Comminication hub site.


Select TeamHub site and associate the site to hub site which we created in the previous steps.




Repeat the same steps for the Finance Hub site.



From the above steps we have associated all the newly created site as hub sites under Parent site


Note:


This is one way of associating the newly created site as hub site in SharePoint admin site. But we can do from the site as well. Open the teamhub site. By using site information option. And from here you can select TestCommunication hub site. Save. Once this option is. Saved you can see the HR hub site appearing over here.



In this post we created hub site and associated the sites to the hub sites. In the next blog we know more details about the how we can provide the same look and feel, how we can move the sites, detach the hub site.

More details about how we can create the Hub site hierarchy in PowerShell

Note:

The steps shown in the image was taken on 28th July 2020, and there might be chances some UI changes in the future.


Saturday, March 9, 2019

A timeout has error occured while invoking commands in sharepoint host process

Recently I faced issue while deploying my sharepoint 2013 solution through Visual studio. During this time feature activation was keep on failing with timeout issue. Initially I thought it might be due to some long running operation in feature receiver code may be causing the issue.

Then I created the package and deployed the solution with powershell script and it went fine, its the time to activate the feature which was giving trouble. First I tried to activate the feature with PS and its worked fine, then deactivated and later tried with UI just to make sure if it breaks out. But no surprises, the feature activated with out any issue.

Now its the time to trouble shoot why its failing in VS2013. Then I started looking into MSDN links and found out there is Registry key called "ChannelOperationTimeout" which take care of time out issue in VS. If we have more feature activation code needs to be executed in during deployment from VS it will break out. Default value set to 120 sec, ideally most of the code should get activated, some times if we are running the code in VM which is allocated with less memory. R/W operation, RAM, free space all these maters while activating the feature from VS. If we have such environment its better to increase the default value of 120 sec to 300 sec(its not mandatory to give 300 sec this worked in my case :)), we can choose any suitable time interval to fix this problem.

Now will provide the steps to change the registry key value.

1) Open Registry editor with admin privilege
2) [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\SharePointTools]
3) Create New Keyword(DWORD) called  ChannelOperationTimeout
4) Set the value to 300(it will be in second)
5) If the key is already present then we need to just update the value.
6) Save the value
7) Restart the machine, since we are updating the Registry value.

Now if we deploy the solution from VS it should work without any error.

Root cause of the issue: Server memory, Disk space, R/W disk

Tuesday, January 8, 2019

Search Error: SearchService.svc is unavailalble

Recently we had an issue in our production environment after windows patching, suddenly search service application went down.
When I open the search service application from central admin I can see below error in System Status

"SearchService.svc is unavailable. This could be because the service is too busy or because no endpoint was found listening at the specified address"

This seems to be looks strange because search application topology seems to be looks good and it doesn't have any issue in there.

As sharepoint developer first thing we look is either event viewer or sharepoint logs, the error reported there was some what misleading or  not  much  relevant information.

So when I checked the Application pool of Managed metadata Service and Search service application both were down. Doing IISReset didn't helped either after manually starting the application pool of each service then all my search service, metadata service and timer jobs which were dependent on these service were back to normal.

Root Cause:

Our Admin team has done the patching of servers in wrong way, like they patched first app server, WFE and later SQL.
Some time sharepoint doesn't understand even though DB server is up and running it will assume its not available for service  application.

The ordering of windows patching should be in proper way else some times sharepoint fails to start the service automatically.

Better way to patching the servers:

1) Take WFE server down
2) All application services hosted server should be taken down
3) Apply the patch in SQL server/s, then if required do restart of servers
4) Apply the patch for APP servers then if required do restart of servers
5) Apply the patch for WFE server/s, then if required do restart of servers.

This is the proper way of doing windows patching, if any follow different approach then these kind of errors will raise.