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


Tuesday, February 14, 2017

Fix for SharePoint 2016 Project Templates Missing in Visual Studio 2015

Problem: SharePoint Project Templates are missing in Visual Studio 2015!
sharepoint project templates missing in visual studio
Solution:
We need to install "Microsoft Office Developer Tools for Visual Studio 2015" for SharePoint 2016 project templates in Visual Studio 2015.
Once installed, You should see SharePoint 2016 project templates in Visual Studio 2015!
sharepoint 2016 project templates missing in visual studio 2015


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


Sunday, January 8, 2017

Get User Account By Display Name in SharePoint

Requirement: Get user by display name in SharePoint
We have a CSV file with list of projects and their Team leads information. This list to be updated on a SharePoint list. But the challenge is 'Team Lead' field has display names of users instead of account name (Domain\LoginID). So prior updating to SharePoint list, we need the Login ID of the user from his display name.

Solution: Lets Query Active directory for the given display name to get the user's Login ID.

Prerequisites: You need to have PowerShell module for Active directory installed to use: Import-Module ActiveDirectory! Use PowerShell cmdlet: Add-WindowsFeature RSAT-AD-PowerShell to add AD Module for PowerShell to your server/desktop! Otherwise, you'll get an error message: "Import-Module : The specified module 'ActiveDirectory' was not loaded because no valid module file was found in any module directory"

PowerShell script to get user accounts from display name and update SharePoint List:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Import-Module ActiveDirectory

#Configuration Variables
$SiteURL = "http://intranet.crescent.com/"
$ListName = "Projects"                
$FieldName="Team Lead"
$CSVFile ="C:\TeamLeads.csv" 

#Custom Function Get User Account from Display Name in AD 
Function Get-UserAccount($DisplayName)
{
    $UserAccount=Get-ADUser -LDAPFilter "(displayName=$DisplayName)" | Select sAMAccountName
    if($UserAccount.sAMAccountName -ne $null)
    {
        return $UserAccount.sAMAccountName.tostring()
    }
    else
    {
        write-host $DisplayName not found in AD! -f Red
        return $null
    }
} 
#Import from CSV file - CSV has Headers ("ProjectName", "TeamLead")
$CSVData = Import-CSV -path $CSVFile

#Get the Target Web & List
$Web = Get-SPWeb -identity $WebURL
$List = $web.Lists[$ListName]
 
#Iterate through each Row in the CSV file
foreach ($Row in $CSVData) 
{
    #Filter by Project Name
 $Item = $List.Items | Where-Object { $_["Project Name"] -eq $Row.ProjectName }
  
 #If the matching project found
    If($Item -ne $null)
    {
  write-host "Searching for:"$Row.TeamLead
  #Get the User Account from Display Name
  $UserAccount = Get-UserAccount $Row.TeamLead
  
  #If User account found in AD
        if($UserAccount -ne $null)
        {
            $TeamLead=$web.ensureuser($UserAccount)
     
      #Update Team member field
   $item["Team Lead"] = $TeamLead
   $item.Update()
         Write-Host "Updated Project:"$Row.ProjectName -ForegroundColor Green
  }
  else
  {
   write-host "No matching User Account Found for :"$Row.TeamLead -f Red
  }
    }
    else
    {
        write-host "No matching List Item Found for:"$Row.ProjectName -f Red
    }  
}
Using SPUtility's ResolvePrincipal Method: Instead of querying Active directory, you can also use SPUtility's ResolvePrincipal method to get a user by display name:
$Web = Get-SPWeb "http://intranet.crescent.com"
$DisplayName="Barunx Romeih"
$Principal = [Microsoft.SharePoint.Utilities.SPUtility]::ResolvePrincipal($web, $DisplayName, "All", "All", $null, $false)
$Principal.LoginName


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