How to get GUID of a Sharepoint Site or Site Collection using PowerShell script in Sharepoint 2007/2010/2013/2016

As we all know there are two ways to get a GUID of a Site or Site Collection
1) Using Powershell
2) Using Sharepoint Central Admin

Writing this post as I had a requirement in office where I had to add some users to a Sharepoint group using a console application.
 
This post explores the first method of obtaining the GUID of a site using powershell script –

Below is the Powershell Script
Add-PSSnapin Microsoft.Sharepoint.Powershell
Write-Host "****** Welcome to Powershell script that gives GUID of a Sharepoint Site ******"
Write-Host ""
$UserEntered = Read-Host -Prompt 'Enter the Sharepoint site with port to get GUID (Press Enter after Pasting) '
$site = Get-SPSite $UserEntered
$siteguid = $site.id
echo $siteguid
Write-Host ""
$User = Read-Host -Prompt 'Press Enter Button to Exit'
Steps to Execute – 

Step 1) Save the above script with suitable filename and extension <fileName>.ps1 
Example - GetSP Site GUID.ps1

Step 2) Right Click on the Script and Select – Run with Powershell


 Step 3) The Script prompts for the Site Name to be entered dynamically, Enter the complete Site URL (along with http and port No)



More blogs about Powershell -

1) How to Check a directory exists and create the folder if it does not exists using Powershell
https://pnsoftwarestudies.blogspot.in/2015/11/check-for-directory-existence-and.html

2) How to create a folder or sub directory using Windows Powershell
https://pnsoftwarestudies.blogspot.in/2015/11/how-to-create-folder-or-sub-directory.html

No comments: