Subscribe:

Labels

Wednesday, August 12, 2020

Get Site Master Pages

 Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

"URL,MasterPage" > "c:\SiteMasterPage.csv" #Write the Headers in to a text file 

#Get All site collections

$SiteCollections = Get-SPWebApplication | Get-SPSite -Limit All

#Loop through all site collections

   foreach($Site in $SiteCollections)

    {

        #Loop through all Sub Sites

       foreach($Web in $Site.AllWebs)

       {

                  write-host "Scanning Site" $web.title "@" $web.URL 

       $web.Url + "," + $Web.CustomMasterUrl  >> c:\SiteMasterPage.csv  #append the data 

                 }

    }

Write-host "Report Generated at c:\SiteMasterPage.csv" -foregroundcolor green 


Detect and Remove inactive AD Accounts

 #Powershell to Remove Orphaned Users from SharePoint 2013/2010


#Load SharePoint Management shell 

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

}

 

#Function to Check if an User exists in AD

function CheckUserExistsInAD()

   {

   Param( [Parameter(Mandatory=$true)] [string]$UserLoginID )

   

  #Search the User in AD

  $forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

  foreach ($Domain in $forest.Domains)

  {

         $context = new-object System.DirectoryServices.ActiveDirectory.DirectoryContext("Domain", $Domain.Name)

         $domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetDomain($context)

     

         $root = $domain.GetDirectoryEntry()

         $search = [System.DirectoryServices.DirectorySearcher]$root

         $search.Filter = "(&(objectCategory=User)(samAccountName=$UserLoginID))"

         $result = $search.FindOne()

  

         if ($result -ne $null)

         {

           return $true

         }

  }

  return $false 

 }

  

 #Change these variables as desired

 #$WebAppURL="http://SharePointWebSite"

 #$RemoveUsers = $false

  

  

  

    

 #Get all Site Collections of the web application

 #$WebApp = Get-SPWebApplication $WebAppURL

$textout = ""

 $textout > "D:\SPO\SharePointOrphanedUsers.csv"

$Farm = Get-SPWebApplication

Foreach ($WebApplicationname in $Farm)

    {

    $WebApp = Get-SPWebApplication -identity $WebApplicationname

    $WebAppSites = $WebApp.Sites

  

 #Iterate through all Site Collections

 foreach($site in $WebApp.Sites)  

 {

    if ($site -ne $null)

    {

        $web = $site.AllWebs

        foreach ($webp in $web)

        {

            $OrphanedUsers = @()

            if (($webp.permissions -ne $null) -and ($webp.hasuniqueroleassignments -eq "True"))

            {

                #Iterate through the users collection

                foreach($User in $webp.SiteUsers)

                {

                    #Exclude Built-in User Accounts , Security Groups & an external domain "corporate"

                    if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and

                            ($User.LoginName.ToLower() -ne "nt authority\system") -and

                                ($User.LoginName.ToLower() -ne "sharepoint\system") -and

                                  ($User.LoginName.ToLower() -ne "nt authority\local service")  -and

                                      ($user.IsDomainGroup -eq $false ) -and

                                          ($User.LoginName.ToLower().StartsWith("corporate") -ne $true) )

                    {

 

                        $UserName = $User.LoginName.split("\")  #Domain\UserName

                        $AccountName = $UserName[1]    #UserName

                         

                        #If the user does not exist in Active Directory then it is an orphaned account in the SharePoint Site Collection

                        if ( ( CheckUserExistsInAD $AccountName) -eq $false )

                        {

                                $textout = """$($User.Name)"",""$AccountName"",""($($User.LoginName))"",""$($webp.URL)"""

                                #Write-Host $textout

                                $textout >> "D:\SPO\SharePointOrphanedUsers.csv"

                                #Make a note of the Orphaned user

                                $OrphanedUsers+=$User.LoginName

                                 

                                 

                        }

                         

                    }

                }

                # ****  Remove Users ****#

                # Remove the Orphaned Users from the site

              #  if ($RemoveUsers)

                #{

                   # foreach($OrpUser in $OrphanedUsers)

                    #{

                       # $webp.SiteUsers.Remove($OrpUser)

                       # Write-host "Removed the Orphaned user $($OrpUser) from $($webp.URL) "

                    #}

               # }

 

            }

 

        }        

                  

    }

}

    }

Get Check-Out files by Web Application Level

 ##########################################################################################################################  

######## V 1.0  

######## PowerShell Script to get a list of checked out files in your SharePoint Environment  

################################################################################################################################  

 

#check to see if the PowerShell Snapin is added  

if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {  

    Add-PSSnapin Microsoft.SharePoint.PowerShell;  

}  

 

## SharePoint DLL   

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")   

$global:currentPhysicalPath = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path  

   

Function Get-SPWebApplication()  

{    

  Param( [Parameter(Mandatory=$true)] [string]$WebAppURL )  

  return [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($WebAppURL)  

}  

   

Function global:Get-SPSite()  

{  

  Param( [Parameter(Mandatory=$true)] [string]$SiteCollURL )  

   

   if($SiteCollURL -ne '')  

    {  

        return new-Object Microsoft.SharePoint.SPSite($SiteCollURL)  

    }  

}  

    

Function global:Get-SPWeb()  

{  

    Param( [Parameter(Mandatory=$true)] [string]$SiteURL )  

    $site = Get-SPSite($SiteURL)  

    if($site -ne $null)  

    {  

        $web=$site.OpenWeb();  

    }  

   return $web  

}  

#EndRegion  

   

 Function GetCheckedOutFiles([string]$WebAppURL)  

 {   

    try  

    {  

        $results = @()  

         

        #Get the Web Application  

        $WebApp=Get-SPWebApplication($WebAppURL)  

  

        #Arry to Skip System Lists and Libraries  

        $SystemLists =@("Converted Forms", "Master Page Gallery", "Customized Reports", "Form Templates",   

                 "List Template Gallery", "Theme Gallery", "Reporting Templates",  "Solution Gallery",  

                 "Style Library", "Web Part Gallery","Site Assets", "wfpub","Site Pages")  

   

        #Loop through each site collection  

        foreach($Site in $WebApp.Sites)  

        {  

            #Loop through each site in the site collection  

            foreach($Web in $Site.AllWebs)  

            {  

                #Loop through each document library  

                foreach ($List in $Web.GetListsOfType([Microsoft.SharePoint.SPBaseType]::DocumentLibrary))  

                {  

                    #Get only Document Libraries & Exclude Hidden System libraries  

                    if (($List.Hidden -eq $false) -and ($SystemLists -notcontains $List.Title) )  

                    {  

                        #Loop through eadh Item  

                        foreach ($ListItem in $List.Items)  

                        {  

                            if( ($ListItem.File.CheckOutStatus -ne "None") -and ($ListItem.File.CheckedOutByUser -ne $null))  

                            {  

                                $sitecollectionUrl =  "<SiteCollection relativeURL=" + $Site.RootWeb.ServerRelativeURL + "></SiteCollection>"  

                                #Create an object to hold storage data  

                                $resultsData = New-Object PSObject  

                                $resultsData | Add-Member -type NoteProperty -name "SiteCollection Title" -value $Site.RootWeb.Title -Force    

                                $resultsData | Add-Member -type NoteProperty -name "SiteCollection URL" -value $sitecollectionUrl -Force              

                                $resultsData | Add-Member -type NoteProperty -name "Web Title" -value $Web.Title -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Web URL" -value $Web.url -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Library Name" -value $List.Title -Force  

                                $resultsData | Add-Member -type NoteProperty -name "File Name" -value $ListItem.Name -Force  

                                $resultsData | Add-Member -type NoteProperty -name "File URL" -value $Web.Site.MakeFullUrl(“$($Web.ServerRelativeUrl.TrimEnd(‘/’))/$($ListItem.Url)”)  -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Last Modified" -value $ListItem['Modified'].ToString() -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Checked-Out By" -value $ListItem.File.CheckedOutByUser -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Checked-Out By User Email" -value $ListItem.File.CheckedOutBy.Email -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Primary Administrator" -value $Site.Owner -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Primary Administrator Email" -value $Site.Owner.Email -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator" -value $Site.SecondaryContact -Force  

                                $resultsData | Add-Member -type NoteProperty -name "Secondary Administrator Email" -value $Site.SecondaryContact.Email -Force  

                                $results += $resultsData   

                            }  

                        }  

                    }  

                }  

                $Web.Dispose()           

            }  

            $Site.Dispose()           

        }  

        $results | export-csv -Path D:\SPO\ListAllCheckedOutFiles.csv -notypeinformation -Force  

         

        #Send message to output console  

        write-host "Checked out Files Report Generated Successfully!"  

    }  

    catch [System.Exception]   

    {   

        write-host -f red $_.Exception.ToString()   

    }   

}  

 

# Function Call  

$WebApp = Read-Host "Enter the web application URL to work on:"  

GetCheckedOutFiles $WebApp  

Thursday, September 27, 2018

Data Loss Protection Policy for SPO/ Online/Office 365, Azure


Problem: With Online and Cloud storage, sensitive user information and company details can be inadvertently disclosed. This results in a non-compliance with business standards and industry regulations as the private data is compromised and can make its way to non-intended users. Securing of sensitive information like Credit Card Number, SSN, Passport Number are of utmost priority while using SharePoint Online for content management.
Solution: Data Loss Prevention(DLP)
Set up DLP Policy: set up the Data Loss Prevention Policy for securing Credit Card information using Rules and Policies in SharePoint Online.
Step1: SharePoint Admin Centre and select Security and Compliance.





Step2: From threat management select ‘Data Loss Prevention’ option.

Step3: Click on the Plus icon to add a new DLP Policy


Step4: By clicking Plus button to add DLP Policy open up a window from where we can select the type of information that we would like to protect.  We can either select already available templates or we can select Custom option to build a custom policy.









Now we should select the services that we would like to protect.  Let’s select SharePoint Online and One Drive.

Setup Rules for DLP Policy:
As part of creating the Policy we should assign specific rules that will catch the sensitive information while in transit. Click on Plus icon to configure the Rule.


Click on Add Condition to add conditions that will form the satisfying condition for the DLP Rule.

Let’s select “Content contains sensitive information” as the main condition that will trigger the Policy.

We can select multiple sensitive information types. We will go ahead with Credit Card Number as the primary sensitive information that we would like to protect.




Now we should specify what action should be taken when the specific rule is met. Click on Add actions to trigger the resulting action.


Let’s select block the content as the first action.







Thus, we have set up the below actions by which the content will be blocked and notification will be sent to end user regarding the same.



We will save the rule by giving it a name and click on OK.

If we want to add more rules we can click on the Plus icon, else click Next.


Now let’s give the DLP Policy a name and click on Create. This will complete the creation of the DLP Policy.




Thus, we have completed the creation of the DLP Rule and the Policy.


Test the DLP Policy:
We can now test the DLP Policy we have created. I have uploaded few documents which contain the sensitive information – Credit Card Number. Upon sharing the document, the DLP policy should get triggered which will block the content and send a notification mail to the end user. To test DLP, let’s Share one of the documents that contains Sensitive information.



In a few minutes time, we will get a mail notification stating that the DLP rule has been matched and it has to be rectified.


Until the sensitive information has been removed from the user, the document access will be restricted to its owner, last modified and the Site owner.

If we go to the Library we can see that a blocked icon has come up against each of the documents that match the DLP Rule.  Unless the specific sensitive information is removed from these documents, it will continue to be blocked from other users.


Clear sharepoint cache


## SharePoint Server 2013: PowerShell Script To Reset The Config Cache On All Servers In A Farm ##


Add-PSSnapin Microsoft.SharePoint.PowerShell
$Servers = Get-SPServer | ? {$_.Role -ne "Invalid"} | Select -ExpandProperty Address
Write-Host "This script will reset the SharePoint config cache on all farm servers:"
$Servers | Foreach-Object { Write-Host $_ }
Write-Host "Press enter to start."
Read-Host
Invoke-Command -ComputerName $Servers -ScriptBlock {
    try {
        Write-Host "$env:COMPUTERNAME - Stopping timer service"
        Stop-Service SPTimerV4
        $ConfigDbId = [Guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\Secure\ConfigDB' -Name Id).Id #Path to the '15 hive' ConfigDB in the registry
        $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath("CommonApplicationData")) -ChildPath "Microsoft\SharePoint\Config\$ConfigDbId"
        Write-Host "$env:COMPUTERNAME - Clearing cache folder $CacheFolder"
        Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item
        Write-Host "$env:COMPUTERNAME - Resetting cache ini file"
        $CacheIni = Get-Item "$CacheFolder\Cache.ini"
        Set-Content -Path $CacheIni -Value "1"
        }
    finally{
        Write-Host "$env:COMPUTERNAME - Starting timer service"
        Start-Service SPTimerV4
        }
}


Rename Site URL in SharePoint


cls
$site = Get-SPSite http://site.qa/site/disposal
#bloomington-in
#Write-Host $site.RecycleBin.Count.ToString();
#$site.RecycleBin.DeleteAll()
$uri = New-Object System.Uri("http://site.qa/site/loomington")
$site.Rename($uri)


Display developer dashboard


$svc = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dds = $svc.DeveloperDashboardSettings
$dds.DisplayLevel = "on"
$dds.Update()