Showing posts with label Sharepoint 2013. Show all posts
Showing posts with label Sharepoint 2013. Show all posts

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

Monday, August 28, 2017

Loading this assembly would produce a different grant set from other instances

Recently in our test environment we encountered this error when we tried  to open the site.

I thought it might be some cache issue or db might got locked for that specific site. So I tried to open sharepoint central admin site then it started throwing this error.

Just before 5 minutes all the sites were working and after that suddenly it stopped after I deployed one of the dll to gac and did an iisreset.

I thought it might be due to latest version of the dll its breaking and I reverted the older version of the dll, but still I was getting the error.

Then I started trouble shooting issue by keep on checking one by one, is there any windows update installed recently, but there was no updates.

So service packs. no language packs no windows updates. Then I check the control panel to see is any other tools/software installed recently, luckily there was tool called Microsoft monitoring agent which is used for SCOM alert.

Our admin team have upgraded SCOM 2012 to SCOM 2016 which is culprit in my case.

Why this will break the application/sites?

Yes why this should break the application. As everyone is aware sharepoint is very complex and brittle in nature. It doesn't allow any other assemblies or any other tool to come in its way.

In our case this monitoring tool tried to inject their assemblies in sharepoint worker process and it caused all the worker process to broke.

In order to fix this issue I asked our admin team to uninstall the SCOM client and install it manually with NO APM=1

This exercise needs to be done in all sharepoint server where its installed.

If any one of you faced this issue and googled out there are plenty resources available which suggest to update registry entry or update web config file of the application.

All the above workaround doesn't work and even if it works we are loosing some thing which we are not aware what might it will break in the future.

Better to avoid all those and tried to verify if any tool/software has been installed recently based on this you can take the decision.