Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. 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