Wednesday, June 7, 2017

SharePoint Online: Site Users and Groups Report using PowerShell

Requirement: Generate a report with all site groups and members of each group of a SharePoint online site collection.

Get all Site Groups and Members of Each group:
#Variables for processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$AdminName = "spadmin@crescent.com"
$SiteURL="https://crescent.sharepoint.com/sites/sales"
 
#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#Get all Site groups
$SiteGroups = Get-SPOSiteGroup -Site $SiteURL

#Get Members of each group
foreach($Group in $SiteGroups)
{
    Write-host "Group:"$Group.Title
    Get-SPOSiteGroup -Site $SiteURL -Group $Group.Title | Select-Object -ExpandProperty Users
} 
To get all users of the site collection, use:
Get-SPOUser -Site $siteURL | select DisplayName, LoginName | Where { $_.LoginName -like "*@crescent.com"}

Get Users and Groups for all SharePoint Online Site Collections:
#Variables for processing
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "SPAdmin@Crescent.com"
 
#User Name & Password to connect
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

Try {
#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#Get all Site collections
Get-SPOSite -Limit ALL | ForEach-Object {
Write-Host "Site Collection:"$_.URL

#Get all Site Groups 
$SiteGroups = Get-SPOSiteGroup -Site $_.URL
   
    #Get Members of each group
    foreach($Group in $SiteGroups)
    {
        Write-host "Group:"$Group.Title
        Get-SPOSiteGroup -Site $_.URL -Group $Group.Title | Select-Object -ExpandProperty Users
    }
  }
}
catch {
    write-host "Error: $($_.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


Sunday, April 16, 2017

Style SharePoint 2016 List View Web Part with Custom CSS

Requirement: Add a custom style to SharePoint 2016's standard list view web part to make it look like a dashboard!

By default, SharePoint list view web part looks dull, isn't it?
sharepoint 2013 list view web part css
So, lets add some custom CSS to the SharePoint 2016 list view, to make it look like a dashboard! How to add CSS to listview? Simple,
  • Click on Site Settings gear >> Edit Page
  • Insert web part >> Choose "Script Editor" under "Media and Content"
  • Place the below CSS code in it. Save and close!
CSS to Brand SharePoint List view:
<style type="text/css">

/* List View Header */
.ms-listviewtable > thead > tr > th {
 background-color: #5B9BD5;
}

/* List view Header Text color*/
.ms-vh-div,  .ms-headerSortTitleLink {
color:white!important; font-weight: bold;
} 

/* background color for alternate rows */
.ms-listviewtable > tbody > tr.ms-alternating {
background: #DDEBF7
}
</style>

Here is the output of the branded List view web part:
sharepoint 2013 add css to listview
Same CSS works for SharePoint 2013 as well.

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


Thursday, March 30, 2017

Find and Replace User ID in SharePoint InfoPath Forms using PowerShell

Requirement: Replace User IDs in InfoPath Forms.

Little background: A particular user's User account changed in Active directory and in SharePoint we ran Move-SPUser cmdlet to accommodate the user's SAM account name change. However, There are many InfoPath form libraries with bunch of InfoPath forms in it - with old user id. Of course, Move-SPUser has no effect on InfoPath Forms!

PowerShell script to search and replace user id in InfoPath XML Forms:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Configuration Parameters
$SiteCollURL="http://intranet.crescent.com"

#Old and New User IDs - CASE SENSITIVE!
$OldUserID="<pc:AccountId>i:0#.w|Crescent\JohnA</pc:AccountId>"
$NewUserID="<pc:AccountId>i:0#.w|Crescent\JonhAbraham</pc:AccountId>"

#Get all webs in the site collection
$WebsColl = Get-SPSite $SiteCollURL | Get-SPWeb -Limit All

#Iterate through each web
foreach($web in $WebsColl)
{
    Write-host "Processing web:"$web.Url
    
    #Get all InfoPath Form Libraries in the web
    $InfoPathLibs = $web.lists | where { $_.BaseType -eq "DocumentLibrary" -and $_.BaseTemplate -eq "XMLForm"} 

    #Loop through each InfoPath form library and Forms (.xml)
    Foreach($Library in $InfoPathLibs)
    {
        Foreach($Item in $Library.Items)
        {
            # Load the contents of the InfoPath Form
            $File = $Item.File
            $Data = [System.Text.Encoding]::ASCII.GetString($File.OpenBinary())
            
            #Check if the File has Old ID
            if($data.Contains($OldUserID))
            {
                $Data = $Data.Replace($OldUserID, $NewUserID)
                $Data = $Data.Replace("???","") #special fix!
                $File.SaveBinary([System.Text.Encoding]::ASCII.GetBytes($Data))

                Write-host "InfoPath XML File updated at $($web.URL)/$($Item.File.URL)"
            }
        }
    }
}


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


Wednesday, March 8, 2017

Fix "Unfortunately, help seems to be broken...There aren't any help collections in the current language for the site you're using." Error in SharePoint 2016

Problem: The Help Menu (?) in SharePoint 2016 is not working! On clicking the Help menu, it gets the error message:
"Unfortunately, help seems to be broken... There aren't any help collections in the current language for the site you're using."
Unfortunately, help seems to be broken... There aren't any help collections in the current language for the site you're using.

Troubleshooting Steps: 
  • Enable External Web-based Help in Privacy Options of SharePoint 2016 Central Admin. Navigate to : http://central-admin-url/_admin/privacy.aspx, and Set "Yes" to "Display Help from external web Sites as specified by each Help collection?"
  • Check the help collection status and install if needed: Open SharePoint 2016 Management Shell, Run:
    Get-SPHelpCollection 

    It gave nothing. Guess help collection is not installed. Now, Install help collection by running:
    Install-SPHelpCollection -All 
wait for few minutes to get them installed (10 min!). Try close and reopen the SharePoint 2016 sites! Now, SharePoint 2016 help should work.



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


Wednesday, February 22, 2017

Rich Text Column in SharePoint Document Library

Problem:
Could not add rich text columns to SharePoint document library, Picture Library and other type of Libraries!

Little background: End user created in document library with type "Description" column as "Multiple lines of text"and expecting this column to is expecting to have the Rich text capability. so, tried editing the column, and found no option to update the type of this column as rich text!
rich text field in sharepoint document library
Troubleshooting:
When you add a Multiple lines of text field to custom list, announcement, tasks, etc, You'll find the Rich text and Enhanced rich text options.
rich text field in sharepoint 2013 document library
However on document libraries, these options seems missing! It just displays a Text area without any formatting! It seems you can't have a rich text column in a document library with SharePoint 2013. So, How do we create Rich Text column for a Document Library?
sharepoint document library rich text field
Solution:
While there are many options to get rich text field in SharePoint 2013 document library like: Custom field types, Content Types, etc, here is the easiest way:
  • Open the site in SharePoint designer, Go to List & Libraries, Click on your library
  • Click on Edit columns under Customization >> Double click on the column which you want enable Rich Text functionality >> select the checkbox which says Rich Text and hit OK and then Save.
sharepoint 2013 document library rich text column
This fixes the problem!

PowerShell way: Setting "RichText" property of the field to True makes SharePoint 2013 document library field rich text enabled!
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SiteURL = "http://intranet.crescent.com/"
$ListName="Documents"
$FieldName="Description" #Internal Name

$Web = Get-SPWeb $SiteURL
$List = $Web.Lists[$ListName]
$Field = $List.Fields[$FieldName]
$Field.RichText = $True
$Field.Update()
sharepoint 2013 document library rich text column
I know this issue exists in all SharePoint versions: Including SharePoint 2007, SharePoint 2010, SharePoint 2013 and even in SharePoint 2016! and Yes, It's weird and I'm not sure why Microsoft hasn't fixed this issue yet!

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...