Thursday, July 30, 2015

How to convert Word documents to PDF by a SharePoint workflow using HarePoint Workflow Extensions.

Introduction
One of the main purposes of SharePoint is collaboration: a group of people can conveniently work with shared documents, making teamwork especially efficient. Usually, text documents are created and edited using Microsoft Word, but when the work is complete, it is convenient to convert the resulting document to PDF. This gives two advantages:
  • No further changes to a document are possible, so it can be safely shared
  • The PDF document can be easily viewed on any device
A Word document can be saved manually as a PDF file right from Microsoft Word’s Save As… menu, but if we talk about tens or even hundreds of documents per week, it would obviously be preferable to have this conversion running automatically. Another thing is that if we browse the short list of workflow actions in SharePoint Designer, we won't find anything related to document conversion. This is where HarePoint Workflow Extensions can help.

Scenario
In this article, we will follow this scenario:
  1. While the team actively works with a document in the document library Active Docs, it has the status "Work in progress". As soon as the job is done the status is set to Completed.
  2. The workflow triggers and converts this Word document to PDF.
  3. When the PDF file has been created, the workflow moves the original Word document to Document Sources library. Only selected team members (such as managers, etc) have access to this document library.
  4. As a result, only the PDF file remains in the original document library, so everyone can view and share this document. This way, the document can be opened easily (also on any mobile device), and at the same time no deliberate or inadvertent changes can be made.
As was mentioned in Introduction, we’re going to use HarePoint Workflow Extensions to perform this automated Word to PDF conversion. So we have the product installed (detailed information about HarePoint Workflow Extensions and its deployment is available on the product homepage: https://www.harepoint.com/Products/HarePointWorkflowExtensions/ and we are ready to go.

Creating a workflow
We can start creating a workflow. This is performed with SharePoint Designer, like we are used to. On the ribbon click New List Workflow for Active Docs list:
A dialog window for creation of a new list workflow will be displayed. Enter a workflow name and optionally a description.  
Important: select the SharePoint 2010 Workflow Platform Type in the drop-down menu, since HarePoint Workflow Extensions uses the 2010 platform type.
Since in our scenario the workflow will be launched every time the document is changed (but not when created), the first action we need to check is whether the document has the Status set to Completed (otherwise no action should be taken).

Add condition If any value equals value:
In the first parameter select Current Item:Status using the lookup:
The second parameter remains equals.

In the third parameter, select Completed:
Now we can add what should be done when this condition is met.

Add a Convert Document action from the HarePoint Activities – Document Conversion category:
In first parameter, select Current Item. Other parameters can be left as default:
The document conversion is not an immediate process, so in order to find out when the conversion has completed, we need to use the Wait Conversion Job action from HarePoint Activities – Document Conversion category:
In the parameter, select Variable:ConversionJobId (it’s the variable that is used in the previous workflow action) using the lookup:   
The workflow will stay on this action until the conversion is completed.
Finally, we will move the original document to Document Sources library that is accessible only for selected team members.

Add action Copy or Move Document from HarePoint Activities – Document Library:
Switch the action from Copy to Move.

In the second parameter (document URL) specify Current Item: Encoded Absolute URL using the lookup:
In the third parameter specify the full URL of the target library:
(typically that looks like http://servername/sitename/subsitename/.../documentlibraryname/)
 Here’s what we have in SharePoint Designer:
Save the workflow. Modify the workflow Start Options in SharePoint Designer to make it run every time the document is changed, but not when created:
Save and Publish the workflow.

Testing a workflow
Now we can make a test. Add a Word document to Active Docs library.

The document will have an empty status field by default (this is how the Status field is set up).
When the work on this document begins, team members edit the document and set the status to Work In Progress:
The workflow triggers, but completes with no actions taken, just as expected.

Now, change the status of the document to Completed:
 First, we notice the workflow status is now In Progress:
 After some time, all the Word document is gone and only the converted PDF remains in Active Docs:
Then, if we take a look at the Document Sources folder (where only selected team members have access), we see the original Word document:
Conclusion
In this article we have reviewed an example of rather simple but efficient workflow for a Team working with shared documents, and have seen how quickly and easily the solution can be achieved by using HarePoint Workflow Extensions – just a couple of actions in SharePoint Designer and no code at all.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Tuesday, July 28, 2015

Product Review: Virto SharePoint Calendar Web Part

Introduction:

Virto SharePoint Calendar Web Part enables users to view all of their events from multiple data sources such as SharePoint Lists, Exchange Calendar, Google Calendar, SalesForce Calendar, SQL Tables or XML and have different views for your easy navigation and reference in one single calendar/or Microsoft Exchange calendars and even from SalesForce Calendars.

Virto SharePoint Calendar replaces the existing SharePoint calendar view's functionality by allowing users to specify the list or view, color code the displayed items by category of events such as internal or external, view day, week, month, year, and Gantt view.

 

Roll up Multiple calendars from different data sources into one Single calendar

The main added value of the SharePoint Calendar web part is the opportunity to have all the events from different data sources displayed in a single SharePoint calendar view, sparing the necessity to switch between multiple views. You can also combine all events from different SharePoint Sites into one calendar! It can show all your events from different SharePoint 2013, 2010 or 2007 lists too.  So you can manage events from different data sources in one calendar.
 
You don't have to synchronize all your calendars from SharePoint, Google, Microsoft Exchange, SalesForce and etc. Install Virto SharePoint Calendar web part and show all the events from multiple data sources in a single place. Use as SharePoint Calendar data sources SharePoint lists from different site collections, SQL tables, Google calendar, XML source, SharePoint lists from other farm, Exchange calendar, SalesForce calendar. This is in comparison to most other SharePoint calendars that can only use one data source, and be displayed in only one view. To distinguish events from different sources in Virto SharePoint Calendar Web Part, one can use multi-level color coding.

Different calendar views (Day, Week, Work Week, Month, Year, Task)

Use appropriate timescale for showing your calendar events. Task view allows to control the status of tasks in your SharePoint Calendar web part. If you need to change the duration of the event, modify the size of the cell to the required direction and length. To change the date, simply select the appropriate date in the mini calendar. All of these features will help you save time and complete your calendar tasks with the greatest convenience. 
Virto provides editing features that will make working with SharePoint easy and pleasant. If you need to change the date of the event, simply drag and drop it to the appropriate calendar cell. To change the event in time frame in SharePoint Calendar, simply expand the event to incorporate the correct duration of the event.

Color coded data sources

You can visualize the events from your calendars. Customize calendar with special colors for each of data sources and your events will not join anymore! This feature is especially essential when you have more than 2 data sources in one calendar. Use any combination of RGB for coloring events according to their category.

Using Virto SharePoint Calendar Web Part
Virto Calendar implemented in a modern style. The component is fully ready for Windows 8 and SharePoint 2013. Installation is simple and only requires a small amount of time. Currently, Virto supports English, German, Spanish, French, Russian and Chinese Simplified languages. It provides color coding feature that displays items in their SharePoint Calendar web part by category of events (such as internal or external, view day, week, month, year, and Gantt view).

You can contact Virto, If you'd like to add another one language to support SharePoint Calendar Web Part!

 

Key Features & Advantages of Virto Calendar Web Part:

Virto SharePoint Web Part Calendar can be used instead of built-in SharePoint Calendar. It provides you with powerful capabilities for more convenient events calendaring, e.g.:
  • Integrate events from different data sources into one single calendar (from SharePoint Lists, SQL Tables and Microsoft Exchange 2013,  2010 and 2007 Calendars)
  • Add, delete and edit events with drag & drop feature 
  • Multi-level color coding - You can add color legend to remember which colors refer to your events. Event coloring according to event data source, according to event type,
  • Day, Year, Month, Week, Work Week, Task (Days), Task (Hours) views
  • Audience Targeting Support 
  • Advanced filtering, displaying only items satisfied to the specific criteria 
  • Print any Calendar View 
  • Adding Event with a single click
  • Event Coloring according to List Type
  • Date Picker for quick and easy navigation
  • Event duration editing with a simple resizing action
  • Event date changing with a just drag and drop
  • Single aggregated view of all your events from different SharePoint Lists not only single SharePoint Site
  • Resizing to accommodate your web page design

System requirements

Virto SharePoint Calendar web part is available in SharePoint versions 2013, 2010 and 2007. Both in Microsoft SharePoint Foundation 2013 and Microsoft SharePoint Server 2013 (or Windows SharePoint Services v3 SP2 or Microsoft Office SharePoint Server 2007) . 

Conclusion:

Virto SharePoint Calendar enables SharePoint users to plan their activities in a fastest way. The functionality and features of the calendar helps to save the time for real business instead of dying under events and other activities.

Virto SharePoint Calendar Web Part is user friendly and has a simple interface, allowing users to easily create new calendar events with a single click! Included with Virto are editing features that will make working with SharePoint easy and pleasant. You can download it a free 30-days trial at: Virto SharePoint Calendar Web Part

Also, VirtoSoftware releases in the next month a new SharePoint Calendar app for Office 365. Useful options and great quality on the new platform! Find the latest news on www.virtosoftware.com


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


SharePoint People Search Results gives "Domain\Account" Instead of User Display Name

Problem:
SharePoint 2010 people search gives "Domain\AccountID" instead of Display name of the user!


Solution:
SharePoint uses "Preferred Name" property which is mapped with "Display Name" property from AD in People search results. Here, I found the root cause of the problem as: User profile not in sync!

Steps to resolve:
  • Make sure in AD, display name field is set properly
  • Go to SharePoint central Administration >> Do a full profile import. 
  • Once you run full profile import, You should see the display name field updated  in user profiles.
  • Run SharePoint search incremental crawl once for the search results to get updated.






You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Find All Lists which Exceeds List View Lookup Threashold in SharePoint

Requirement:
Resource throttling feature in SharePoint controls resource usage on SharePoint Farm for optimum usage. My requirement was to find all lists which are exceeding configured list view lookup threashold limit in SharePoint.

PowerShell script to find All Lists which are Exceeding List View Lookup Threashold:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Get the Web Application
$WebApp = Get-SPWebApplication "http://portal.crescent.com"
 
#Array to Hold Result - PSObjects
$ListResults = @()

#Get the Throttling Limit of the Web App
$Threshold = $WebApp.MaxQueryLookupFields
 
    foreach($Site in $WebApp.Sites)
    {
        foreach($Web in $Site.AllWebs)
        {
            Write-host "Scanning site:"$Web.URL
             
            foreach($List in $Web.Lists)
            {
    #Get Number of Lookup Fields
    $LookupFields = $List.Fields | Where { $_.TypeDisplayName -eq "Lookup" -and $_.Hidden -eq $false}
                if($LookupFields.Count -gt $Threshold)
                {
                    $Result = New-Object PSObject
                    $Result | Add-Member NoteProperty Title($list.Title)
                    $Result | Add-Member NoteProperty URL($web.URL)
                    $Result | Add-Member NoteProperty Count($LookupFields.Count)
                     
                    #Add the object with property to an Array
                    $ListResults += $Result
                }
            }
        }
    }

Write-host "Total Number of Lists Exceeding Lookup Threshold:"$ListResults.Count -f Green
#Export the result Array to CSV file
$ListResults | Export-CSV "c:\ListData.csv" -NoTypeInformation  
This script produces a CSV file with all List Name, their URLs and number of lookup columns where the list exceeds maximum count configured in web application throttling settings in SharePoint 2013 central administration site.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Monday, July 27, 2015

Mount-Dismount (Attach-Detach) Content Databases in SharePoint using PowerShell

As stsadm is deprecated in SharePoint 2013, We should use below Powershell cmdlets to  to attach-detach content databases in SharePoint:

Mount-SPContentDatabase
The Mount-SPContentDatabase cmdlet attaches an existing content database to the specified Web application in the SharePoint farm. If the database being mounted requires an upgrade, this cmdlet upgrades the database automatically. We use this cmdlet when:
  • During Migrations when you want to attach (or associate) the content database with new build (or new platform). E.g. Database attach upgrade
  • Move a content database from one database server to another, E.g. You got the database backup of a SharePoint site from your client and want to use that database in your environment
  • When we attach a content database to a different web application.
Important: Before using Mount-SPContentDatabase, make sure you restored the database to your SharePoint Database Server (SQL Server) first!

Mount-SPContentDatabase syntax to attach a content database:
Mount-SPContentDatabase -Name "Content-database-name" -DatabaseServer "db-server-name" -WebApplication "Name-of-the-webapp"
E.g.
Mount-SPContentDatabase -name "SP2010_Intranet_Content" -DatabaseServer "G1-SP-SQL01" -WebApplication "http://migration.crescent.com" -confirm:$false
This PowerShell command attaches content database "SP2010_Intranet_Content" to the SharePoint 2013 web application "http://migration.crescent.com". By default, Mount-SPContentDatabase cmdlet upgrades the schema of the database to the destination build and upgrades all site collections within the specified content database, if required!

To attach content database using STSADM, use:
stsadm -o addcontentdb -url http://SharePoint.company.com -databasename <MOSS2007_Migration_Content>

Dismount-SPContentDatabase
Dismount-SPContentDatabase is the reverse of Mount-SPContentDatabase. It detaches the given content database from the specified web application. This cmdlet just updates the mapping between web application and content database but doesn't actually delete the database from SQL server.

Dismount-SPContentDatabase syntax to detach content database:
Dismount-SPContentDatabase -Name "Content-database-name"
E.g. Here is how to detach content database in SharePoint 2010
Dismount-SPContentDatabase -Name "SP2010_Intranet_Content"
This PowerShell cmdlet removes content database from SharePoint .

If you still want to use STSADM to detach content database in SharePoint, use:
stsadm -o deletecontentdb -url http://SharePoint.company.com -databasename <MOSS2007_Migration_Content> 

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Sunday, July 26, 2015

How to Get All Lists in SharePoint Site using PowerShell

Get all lists in SharePoint site using PowerShell:
To get all SharePoint lists by using PowerShell, use this script:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Configuration Variables for Web URL
$WebURL ="https://sharepoint.company.com/"

#Get the site
$Web = Get-SPWeb $WebURL

#Get all sharepoint lists by using powershell 
$ListCollection = $Web.Lists

#sharepoint powershell loop through all lists
Foreach($list in $ListCollection)
{
 #get list details 
 Write-host $List.Title - $list.ItemCount - $List.Author.Name
}

One-Line Script to get all Lists in SharePoint using PowerShell:
(Get-SPweb "https://sharepoint.company.com/").Lists | ForEach-Object { Write-Host $_.Title}

SharePoint PowerShell to get all lists in site collection:
PowerShell to get all lists in site collection
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#Configuration Variables for Site Collection URL
$SiteURL ="https://sharepoint.company.com/sites/Sales"
$Site = Get-SPSite $SiteURL

#Iterate through each web in the site collection
foreach($Web in $Site.AllWebs)
{
 Write-Host $Web.Url -ForegroundColor DarkRed
 
 #Loop through each List in the site
 foreach($List in $Web.Lists)
 {
  Write-Host $list.Title -ForegroundColor Blue
 }
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Show Status Message in SharePoint 2013

Requirement: After the launch of new SharePoint intranet portal, we wanted to display a status message in each page.

Solution: Here is the script to display status message using SharePoint Javascript client side object model.
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(AddStatusMessage, "sp.js");

function AddStatusMessage()
{
var statusID = SP.UI.Status.addStatus("Welcome","Welcome to New Crescent Portal. Feel free to contact <a href='mailto:support@crescent.com'>Helpdesk </a> if you have any queries");

SP.UI.Status.setStatusPriColor(statusID, 'green');
}
</script> 

and the result of SharePoint 2013 status message:
sharepoint 2010 status message
This script can be used in Master pages or in Script editor web parts.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 24, 2015

Change Subsite logo to Link Root Site in SharePoint 2013 / 2016 using jQuery

Requirement: Change Subsite logo to link root site in SharePoint 2013 / SharePoint 2016

Solution: By default, Subsite logo links points to its homepage. We can change site logo link in SharePoint 2013 using jQuery to point to root site.
sharepoint 2013 logo link to root
Change SharePoint 2013 logo link to root site:
Add a script editor or modify your master page to include this code
<script src="http://code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
  $("#DeltaSiteLogo a").attr("href","http://intranet.crescent.com/");
});
</script>

Here is my another post with different approach: Change SharePoint 2013/2010 Site Logo Link to Root Site URL

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, July 23, 2015

SharePoint Online: Update List Items using PowerShell

PowerShell CSOM Script to update List Items in SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
#Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/"
$ListName="Projects"

$UserName="admin@crescent.com"
$Password ="Password goes here"
 
#Setup Credentials to connect
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))
 
#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
$Context.Credentials = $credentials

try{ 
  
    #Filter and Get the List Items using CAML
    $List = $Context.web.Lists.GetByTitle($ListName)

    #Get List Item by ID
    $ListItem = $List.GetItemById(1)  

    #Update List Item title
    $ListItem["Title"] = "Item Title Updated"  
    $ListItem.Update()  

    $Context.load($ListItem) 
    $Context.ExecuteQuery()
    write-host "Item Updated!"  -foregroundcolor Green  
}
catch{  
    write-host "$($_.Exception.Message)" -foregroundcolor red  
}   


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 17, 2015

Apply Theme in SharePoint 2013 using PowerShell

Themes are the quick and easiest way to apply branding to SharePoint sites. In SharePoint 2013 Themes got changed and redesigned as "Composed Look" feature. As it sounds "Composed" look, it simply defines theming by combining design elements: Master page - AKA site layout, Color theme, Font schemes and background images. Read more: http://www.sharepointdiary.com/2014/12/sharepoint-2013-composed-looks-feature.html

Apply composed look programmatically in SharePoint 2013  
If you want to uniformly apply the composed look which comprises of Master Page, Image file, Font schema to all sites, you can utilize PowerShell.
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Variables for processing
$WebURL="http://portal.crescent.com/"
$ColorPaletteURL="/_catalogs/theme/15/Palette015.spcolor"
$FontSchemeURL="/_catalogs/theme/15/fontscheme005.spfont"
$BackgroundImgURL="/_catalogs/theme/15/Tulips.jpg"

#Get the Web
$web = Get-SPWeb $WebURL

#Apply theme
$web.ApplyTheme($ColorPaletteURL, $FontSchemeURL, $BackgroundImgURL, $true)
$web.Update()
This applies the theme for given web.
change theme in sharepoint using powershell


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Configuring Visio Graphics Service Application in SharePoint 2013 using PowerShell

Visio diagrams are wonderful way to express ideas, simplify complex topologies, illustrate the process flow, etc. With Visio Services in SharePoint 2013, you can publish Visio diagrams in SharePoint so that they can be Shared and viewed online without installing Visio application in client computers.

Configuring Visio Services in SharePoint 2013
Provisioning Visio services is straight-forward. Head on to SharePoint 2013 Central Administration site, Application Management >> Service Applications >> Manage Service Applications >> Click on "New" and choose "Visio Graphics Services"
Visio Graphics services available only in SharePoint 2010/2013 Enterprise Edition! Make sure "SharePoint Server Enterprise Site features" is activated both at site collection level and site level.
Visio Graphics service application in SharePoint 2013
Fill the form with Service application name, choose Service application pool and other details. Click on "OK" to complete creation of visio service application.
Configuring Visio Services in SharePoint 2013
SharePoint 2010 allowed only .VDW Visio drawing files to be published to SharePoint. With SharePoint 2013 you can also publish .vsdx files directly!

Create Visio Graphics Service in SharePoint 2013 using PowerShell:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#Start the service instance
Get-SPServiceInstance | Where{$_.TypeName -like '*Visio*'} | Start-SPServiceInstance

#Create new Service Application Pool
New-SPServiceApplicationPool -Name "Visio Services" -Account "Crescent\SPS_Services" 

#To Re-use any existing App Pool, use: $ServiceAppPool = Get-SPServiceApplicationPool "Service Application Pool"

#Create Visio Service Application
$VisioServiceApp = New-SPVisioServiceApplication -ApplicationPool "Visio Services" -Name "Visio Service Application"

#Create Service Application Proxy
New-SPVisioServiceApplicationProxy -ServiceApplication "Visio Service Application" -Name "Visio Service Application Proxy" 

To confirm everything is up and running, Go to the "Services on Server" page in the SharePoint 2013 Central Administration and make sure "Visio Graphics Service" is marked as started and under Service Applications list "Visio Graphics Service Application" is listed.

SharePoint 2013 Visio service application:
 sharepoint 2013 configure visio services

SharePoint 2013 Visio unattended service account:
If your visio diagram uses data connectivity, You must create a application id under secure store services for visio graphics services unattended operations.

Grant permissions to Visio Service account on All web applications
Make sure the service account you used for visio graphics service application is granted with dbo access to all content databases of all web applications in order to render visio web drawing. 
#Visio service Account
$VisioServiceAccount = "Crescent\VisioAppPoolAccount"

#Iterate through All Web Application
Get-SPWebApplication | Foreach-Object {
  #Grant access to each web app    
 $_.GrantAccessToProcessIdentity($VisioServiceAccount)
 $_.Update()
} 
How to Publish Visio Files in SharePoint 2013: 
Upload your Visio drawings (either VDW or VSDX) to any SharePoint Library. SharePoint 2013 should render visio file in browser!


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, July 16, 2015

Configure Audit Settings for SharePoint 2013 Sites using PowerShell

Audit log feature in SharePoint helps us to analyze how SharePoint contents are being used by users or to track documents and users in accordance to compliance requirements. SharePoint 2013 audit log configuration is explained in my another post: Configuring Audit Logs Feature in SharePoint 2013 . Lets see how to enable auditing feature in SharePoint 2013 using PowerShell.

PowerShell to set SharePoint 2013 Audit Log Settings
To set SharePoint 2013 site collection audit settings using PowerShell, use this script:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$SiteCollURL="http://intranet.crescent.com"

#Get the site collection
$Site = Get-SPSite $SiteCollURL

#Define Audit Events
$AuditLogEvents = "Delete", "Update" 

$Site.Audit.AuditFlags = $AuditLogEvents
$Site.Audit.Update()

#Set Trimming Options
$Site.TrimAuditLog = $true
$Site.AuditLogTrimmingRetention = 10

Configure Audit log Settings for All Sites in SharePoint 2013
$WebApp = Get-SPWebApplication "http://sharepoint.company.com"
$AuditMask = [Microsoft.SharePoint.SPAuditMaskType]::Delete -bxor [Microsoft.SharePoint.SPAuditMaskType]::Update -boxr [Microsoft.SharePoint.SPAuditMaskType]::SecurityChange

$WebApp.sites | % {

$_.TrimAuditLog = $true
$_.Audit.AuditFlags = $auditmask
$_.Audit.Update()
$_.AuditLogTrimmingRetention = 30
}
}

For all available audit masks, refer MSDN: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spauditmasktype.aspx

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, July 15, 2015

Disable Alerts on SharePoint 2013 List using PowerShell

Requirement: Temporarily disable Alert Emails on a SharePoint list.

Solution:
SharePoint Alert objects have "Status" property which can be turned ON or OFF. As there is no UI to disable or enable alerts in SharePoint directly from the browser, we can do it programmatically with PowerShell. Here is my PowerShell script to disable alerts on SharePoint 2010/2013 list or library.
Important: This script disables ONLY existing alerts in a specific list or library! It doesn't (of course, can't!) disable any new alerts you create on the particular list! You may have to temporarily turn-off alerts on web application level by changing the flag "AlertsEnabled" to "false" as in How to Disable Alerts in SharePoint
PowerShell script to Disable alerts on SharePoint list
Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue

#Function to Disable All Active Alerts on a Given List
Function Disable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are Active
    $ListAlerts = $Web.Alerts | Where-Object {($_.List.Title -eq $List.Title) -and ($_.Status -eq "ON")}

    Write-host "Total Number of Active Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="OFF"
            $Alert.Update()
            write-host "Disabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Function to Enable all Disable Alerts on a Given List
Function Enable-ListAlerts($WebURL, $ListName)
{
    #Get the Web and List objects
    $Web = Get-SPWeb $WebURL
    $List = $web.Lists.TryGetList($ListName)

    #Get All Alerts created in the list - Which are in Disabled State
    $ListAlerts = $Web.Alerts | Where-Object { ($_.List.Title -eq $List.Title) -and ($_.Status -eq "OFF")}

    Write-host "Total Number of Disabled Alerts Found in the list: $($ListAlerts.Count)" 
    
    #Iterate through each alert and turn it OFF
    foreach($Alert in $ListAlerts)
        {
            $Alert.Status="ON"
            $Alert.Update()
            write-host "Enabled the Alert' $($Alert.Title)' Created for User '$($Alert.User.Name)'"
        }
         
    #Dispose web object
    $Web.Dispose()
}

#Variables
$WebURL = "http://operations.crescent.com/"
$ListName="Proposal Documents"

#Call the function Appropriately to Disable or Enable Alerts 
Disable-ListAlerts $WebURL $ListName

#To Enable it back
#Enable-ListAlerts $WebURL $ListName

Related Posts:


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 10, 2015

Restore Deleted Items from Recycle Bin in SharePoint Using PowerShell

How to restore deleted items from SharePoint recycle bin?
  • To restore deleted items, Click on "Recycle Bin" link on the Quick Launch.
  • Locate the object that you want to restore by Selecting the check box next to the object and then click Restore Selection.
    sharepoint restore from recycle bin powershell
SharePoint 2010 - Restore from recycle bin using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration variables
$SiteURL="http://portal.crescent.com/sites/ops/"
$ItemName="Classifieds.xlsx" #Can be a List Name, File Name or ID of an Item

#Get Objects
$site = Get-SPSite $SiteURL
$RecycleBin = $site.RecycleBin

#Get the Item from Recycle bin
$Item = $RecycleBin | Where{$_.Title -eq $ItemName}

if($Item -ne $null)
{
 $Item.Restore()
 Write-Host "Item Restored from Recycle Bin!" -f DarkGreen
}
else
{
 Write-Host "No Item Found with the given name!" -ForegroundColor RED
}
This script restores given items from recycle bin.

Tips: How to find and restore all items deleted by a particular use? Use: $RecycleBin | Where { $_.DeletedBy -like "Domain\Account" }

Restore based on Object Type (such as List, Web, ListItem, etc)
What if you want to restore all deleted lists or deleted sub-sites from the Recycle bin? Here is the PowerShell script to restore all deleted lists from SharePoint 2013 recycle bin.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration variables
$SiteURL="http://portal.crescent.com"

#Get Objects
$site = Get-SPSite $SiteURL
$RecycleBin = $site.RecycleBin

#Get All deleted Lists from Recycle bin
$DeletedItems = $RecycleBin | Where{ $_.ItemType -eq "List"}
if($DeletedItems)
{
 Foreach($Item in $DeletedItems)
 {
  $Item.Restore()
  Write-Host "'$($Item.Title)' Restored from Recycle Bin!" -f DarkGreen
 }
}

PowerShell to restore all items from SharePoint Recycle bin:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SiteURL="http://portal.crescent.com/sites/operations"
$Site = Get-SPSite $SiteURL

#Get All Recycle bin items
$DeletedItems = $Site.RecycleBin

if($DeletedItems)
{
 foreach($Item in $DeletedItems) 
 { 
  $Site.RecycleBin.restore($Item.ID)
  Write-Host "Item restored:"$Item.Title
 }
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Friday, July 3, 2015

Delete SharePoint User Profile using PowerShell

Generally SharePoint user profiles will get deleted when any of the below incident happens:
  • User account is deleted in Active Directory
  • Account is disabled
  • User Profile Service Application Connection is changed or recreated
  • Account is recreated in AD or moved out of an OU which is not part of SharePoint User Profile sync connection
At times, You may have to delete SharePoint user profiles manually.

PowerShell to Delete a User Profile in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://mypage.crescent.com"
$UserLogin="Crescent\Sherif"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Get the User Profile
$UserProfile = $UserProfileManager.GetUserProfile($UserLogin) 
#remove user profile
#Get User Profile $ProfileManager.RemoveUserProfile($AccountName);  

Delete all user profiles in SharePoint
In an another scenario, I got a requirement of cleaning up user profile store. Although many profiles exists in user profile store, they were not shown in SharePoint 2013 Central administration. So, Deleting orphan/corrupted user profiles from  Central administration is not possible.  To remove all user profiles, use this PowerShell script:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Variables
$SiteURL = "http://mypage.crescent.com"

#Get Objects
$ServiceContext  = Get-SPServiceContext -site $SiteURL
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)

#Ger all User Profiles
$UserProfiles = $UserProfileManager.GetEnumerator()
 
# Loop through user profile
Foreach ($Profile in $UserProfiles ) 
{
    write-host Removing User Profile: $Profile["AccountName"] 
    
    #Remove User Profile
    $ProfileManager.RemoveUserProfile($profile["AccountName"])
}


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Thursday, July 2, 2015

Move Site Collection to Another Content Database using PowerShell

Requirement: Found a SharePoint Site collection growing in size over a period of time and wanted to move the SharePoint 2013 site collection to another content database.

Solution: Use the PowerShell Cmdlet Move-SPSite to move site collection from one content database to another. Here is how: First, Identify the target content database to move your site collection. You can create new content database with New-SPContentDatabase cmdlet. Next, Run Move-SPSite cmdlet with site collection URL and database name parameters.

Syntax:
Move-SPSite <Site-Collection-URL> –DestinationDatabase "<Database-Name>"
Example:
Move-SPSite "http://intranet.crescent.com/sites/ops" –DestinationDatabase "SP13_Intranet_Content08"
Here is our script in action:
move site collection to another content database sharepoint 2010 using powershell
Tips: To find the current database of the site collection, use: Get-SPSite "Site-collection-url" | Select ContentDatabase

Here is an alternate approach: Move SharePoint Site Collections between Content Databases

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


How to Use JSLink with List View Web Part in SharePoint 2013

What is JsLink in SharePoint 2013:
JSLink is a new method of combining JavaScript, CSS and HTML elements together to customize the look and feel of SharePoint Fields, List Items, List views, List forms and web parts.
 
How to use JSLink in SharePoint 2013?
Here is the SharePoint 2013-jslink example. Lets customize the look and feel of static "% Complete" to bar chart with the help of JSLink. At high-level, here are the steps:
  1. Create a JavaScript override file
  2. Upload the JavaScript file to the "Master Page Gallery >> Display Templates", Set the content type and properties of the file.
  3. Set the JS Link property of the List view web part to point to the JavaScript file we've uploaded.

Step 1: Create your custom JS file to render SharePoint list field
As the first step, We'll have to create a new js file which customizes the rendering of our field. Here is what I've created "TaskListDT.js".
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'PercentComplete': { 'View': renderPercentComplete }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function renderPercentComplete(ctx) {
 
    var fieldVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    var percentComplete = fieldVal.toString().replace(" ", "");
 
    var html = '';
    html += "<div style='width:100%;height:20px;border:1px solid #AEAEAE;position:relative;'>";
    html += "<div style='background-color:#0072C6;height:100%;width:" + percentComplete + ";'></div>";
    html += "<p style='width:100%;text-align:center;position:absolute;top:0px;left:0px;margin:0px;'>";
    html += percentComplete;
    html += "</p>";
    html += "</div>";
 
    return html;
}

Step 2: Upload the JS file to Display Templates Folder
Navigate to Site Settings >> Click on "Master pages" link. >> Navigate to "Display Templates" folder >> Upload your custom JS file. (It could be uploaded to anywhere in the site!)

While uploading, Make sure you set the properties of the JS file. Set the content type as "JavaScript Display Template" and supply other required parameter values as in the below screen.sharepoint 2013 how to use jslink

Step 3: Set JS Link property of List View Web part in SharePoint 2013
The next step is to specify the location of your JavaScript file in the List view web part property. Be sure you follow the "~sitecollection/Your-JS-File-complete-Path" format! (Can also use: ~site, ~layouts, ~siteLayouts, ~siteCollectionLayouts tokens)
jslink list view sharepoint 2013

Here is the Typical "% Complete" column from SharePoint 2013 task list:
sharepoint 2013 jslink property
and Here is our output - Bar charts for "% Complete" column.
sharepoint 2013 list view webpart jslink
In earlier versions of SharePoint (SharePoint 2007, SharePoint 2010), we used to customize XSL for such requirements. Here is one among them: Building Bar chart to Display Progress in Task List

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Wednesday, July 1, 2015

Upload Files to SharePoint Library Remotely using Client Object Model (CSOM) and PowerShell

Requirement: Upload files to SharePoint document library remotely.

PowerShell Script to Upload a File to SharePoint Library using Client Object Model:
We can upload files to SharePoint Online or SharePoint on-premises document libraries remotely using PowerShell and client side object model (CSOM). 
#Load SharePoint CSOM Assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null

##Variables for Processing
$SiteUrl = "http://mgmt.crescent.com/"
$LibraryName="Proposal Documents"
$SourceFile ="D:\Reports\MonthlyRpt.csv"

#Setup Credentials to connect
$Credentials = [System.Net.CredentialCache]::DefaultCredentials  #Current User Credentials
#connect using user account/password
#$Credentials = New-Object System.Net.NetworkCredential($UserName, (ConvertTo-SecureString $Password -AsPlainText -Force))
#For Office 365, Use:
#$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,(ConvertTo-SecureString $Password -AsPlainText -Force))

#Set up the context
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) 
$Context.Credentials = $credentials
$web = $Context.Web

#Get the Library
$List = $web.Lists.GetByTitle($LibraryName)
$Context.Load($List)
$Context.ExecuteQuery()
    
#Get File Name from source file path
$SourceFileName = Split-path $SourceFile -leaf 

#Get Source file contents
$FileStream = ([System.IO.FileInfo] (Get-Item $SourceFile)).OpenRead()

#Upload to SharePoint
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.ContentStream = $FileStream
$FileCreationInfo.URL = $SourceFileName
$FileUploaded = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($FileUploaded)
$Context.ExecuteQuery()

#Set Metadata
$properties = $FileUploaded.ListItemAllFields;
$context.Load($properties)
$properties["Category"]="Reports"
$properties.Update() 
$context.ExecuteQuery()
 
#Close file stream
$FileStream.Close()
Important: Make sure you have SharePoint 2013 Client Components SDK installed in your client machine prior running this script!

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


You might also like:

Related Posts Plugin for WordPress, Blogger...