Extract Documents to Folder based on Managed Metadata Column - SharePoint

Image
  How to Extract documents from Multiple Document libraries in to Folders. Each has a Managed Metadata Column with Sub Terms. I have created three Functions to  Download Document Create Folder Main Method Addition to above, script will log the Document URL and destination Folder Path in .log file Create Folder   Function   Create-Folder {      param  ( $folderPath )      if  (!( Test-Path  -path  $folderPath ))     {          New-Item   $folderPath  -type directory     } } Download Document ( this is stolen from Stackoverflow 😁 ) Function   Download-Document {      param ( $web ,  $folderPath ,  $docItem )       #File Download Snippet Reffered From : https://stackoverflow.com/questions/43350575/how-to-use-powershell-to-download-files-from-sharepoint        $File  =  $web .GetFile ( $docItem .Url )          $Binary  =  $File .OpenBinary ()          $detinationPath  =  $folderPath  +  "\"  +  $File .Name ;          $Stream  =  New-Object  System.IO.FileStream( $detinationPath

SharePoint 2013 Site Response Time- Home Page - PowerShell


I wanted to Verify the response time of the all home pages of my Entire Farm using PowerShell Script.

with little bit of Google I was able to find out all the required components for me to come up with the Response time of the Each site home page for entire Farm

few of the key sections which I was looking in google were Response time

$TimeResponse = Measure-Command -Expression {
                    $Response = invoke-webrequest -Uri $web.Url -UseDefaultCredential ;

Basic Logic of the Script is based on Response code (200 for success) I'm writing in to a text file about the time taken to response from web site home page.

Entire Script came up as follows including Logs

Add-PSSnapin Microsoft.SharePoint.PowerShell

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

cls;

$timeStamp = Get-Date;
$startTime = $timeStamp.ToString("yyyy-MM-dd-HH-mm:s");
$ExecutionID = $timeStamp.ToString("yyyyMMddHHmm"); 

Write-Host $startTime

 $logFilePath = "… \$ExecutionID-SiteAvailability.log";

Add-Content -Path $logFilePath -value "WebApplication | SiteCollection |FirstLevelSubSite | StatusCode | Status Description | Response Time |Exception | Created |Last modified";

 function ValidateSites()
{

    $allSiteCollections = Get-SPSite -Limit All

    $Response = $null ;
    $error = "";
    $siteCreated = "";
    $siteModified = "";

    foreach ($sitecollectoin in $allSiteCollections)
    {
        $siteCollURL = $sitecollectoin.URL;
         $allTopWebs = $sitecollectoin.AllWebs;

        foreach ($web in $allTopWebs)
        {  
            TRY {

                $TimeResponse = Measure-Command -Expression {
                    $Response = invoke-webrequest -Uri $web.Url -UseDefaultCredential ;

                }
                IF ($Response.StatusCode -eq "200")
                {
                    Write-Host "URL: " $web.Url " -Status:" $Response.StatusCode " Response Time (ms): "$TimeResponse -f Green;
                }
                ELSE
                {              
                    Write-Host "URL: " $web.Url " -Status:" $Response.StatusCode " Response Time (ms): "$TimeResponse -f Red;

                }

                $siteCreated = $web.Created;
                $siteModified = $web.LastItemModifiedDate;
               
            }
            CATCH [Exception]
            {
                write-host -f red $_.Exception.ToString() ;
                $error = $_.Exception.ToString();
            }
            FINALLY
            {
                 Add-Content -Path $logFilePath -value "$($sitecollectoin.WebApplication.Url) | $($siteCollURL) |$($web.Url) | $($Response.StatusCode) | $($Response.StatusDescription) |$($TimeResponse)| $($error) |$($siteCreated) | $($siteModified)";

                $Response = $null;
                $error = "";
                $web.Dispose()

            }
        }

         $web.Dispose()

     }

}

#Calling the Method written in above section to execute and get each site 
#response time
ValidateSites;


$timeStamp = Get-Date;
$endTime = $timeStamp.ToString("yyyy-MM-dd-HH-mm:s");


Write-Host $startTime;
Write-Host $endTime;


Pre-Upgrade Check List

Download Our Free SharePoint Pre-Upgrade Check List

* indicates required

Vintage Clan

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): The EXECUTE permission - User Profile Issue

How to Create Host Header to SharePoint Web Application

SharePoint 2013 Access Denied in Site Collections in Web Application