Saturday, 28 October 2017

Post SharePoint Items into MS Teams using MS Flows

Views

Posting SharePoint Items as Conversations in Microsoft Teams


Here let us see how to push the items from SharePoint into the Microsoft Teams Channels as conversations using Microsoft Flows. #MicrosoftTeams #MicrosoftFlow

This is simple, straight forward and out of the box approach. Microsoft Flow eases our job with out of the box configuration.

Consider a business scenario, whenever an item is created in the SharePoint repository, it has to be pushed into Microsoft Team’s channel for discussions. The following steps will helps you in configuring the flow out of the box.

Note: Assuming, the connections for teams and SharePoint services are being available in the Microsoft Flow portal. If not already created, you will be prompted to provide the account details when configuring the SharePoint or the Microsoft Teams components in the below steps. You can provide different or the same account details. The accounts to the SharePoint or Microsoft teams can also be configured on the Microsoft Flows portal by navigating to the connections component.

Steps Involved:

  • Create a list in the SharePoint site.
  • Create a channel in the Microsoft teams.
  • Login to the Microsoft flows.
    • Select the SharePoint service à "when an item is created" template.
    • Provide the site details and list details.
    • Click on New Step à Add an action option.
    • Search for Microsoft teams and select it.
    • Select Post Message option.
    • From the drop down select the Microsoft Teams ID, Channel ID, and Message to be posted.
    • Here, message to be posted can be customized. Click on the message text box and select the SharePoint item field by adding dynamic content. (picture shown below)
  • Save the flow.


Test the Flow:

  • Login to the SharePoint site and navigate to the list.
  • Create an Item à Provide some data and save it.
  • Login to the Microsoft Teams and navigate to the channel provided in the configuration.
  • You can see the item created in the SharePoint list, posted as a conversation in the Team’s channel.





Thursday, 26 October 2017

Removing Web Part from SPFx Solution

Views
You would have seen adding web parts to the SharePoint framework solutions. Here, let us see how to remove the web part from the SharePoint framework solution manually.

Web Part Files:

  • Navigate to your SPFx solution and the web parts folder inside it. (\src\webparts\)
  • Locate your web part folder and delete it. (This will delete all the files created for your web part)

Configuration File Entries:

  • Next, web part bundle needs to be removed from the config file (config.json).
  • In the config.json, locate your web part entry and remove the same. 
  • Similarly remove the localization file entry from the config file. 
For example, helloworld web part entry will look like,



Library Files:

  • Corresponding files should also be removed from the library folder.
  • Navigate to /lib/webparts/ folder in the solution. Locate your web part and delete the same.



Wednesday, 18 October 2017

Working With SharePoint Site Collections On Office365 Tenant Site Using PnP PowerShell

Views
In this article, you will learn how we can create, retrieve, update and delete SharePoint site collections on Office 365 tenant, using PnP PowerShell. The Client Side Object Model is used internally for these operations.

Prerequisite:

You need to have PowerShell 3.0, available on a Windows machine. You need to install or import PnP PowerShell packages. You can download the installers or view more documentation on the official site. The installers are available here. Online version installer is preferred. You can also install all the three installers for testing (SharePoint 2013, 2016, online).

The PnP PowerShell is supported from SharePoint 2013 On Premise and Office 365 versions. The following operations are compatible/tested on Office 365 environments/sites. These operations are not supported by On Premise versions.

Connect To Tenant Site:

To create, retrieve or modify the site collections, we need to connect to the SharePoint tenant (admin) site on Office 365, using the snippet given below. PnP PowerShell code, given below, helps in getting the current context of the admin site, using the Client Side Object Model (CSOM):
  1. $siteurl = "https://abc-admin.sharepoint.com"  # Tenant Admin URL  
  2. Connect-SPOnline -Url $siteurl    
  3. $ctx = Get-SPOContext  
Once connected, you can carry out any of the operations mentioned below, based on the requirement.

The site collections can be accessed from the site collections page (The URL will look like https://abc-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx). 

Retrieve Site Collections:

From the admin site, the available site collections can be retrieved, using PnP CSOM PowerShell.
Get-SPOTenantSite command is used to retrieve the site collections from the O365 SharePoint tenant site. The optional parameters used to retrieve the site collections are 
  • Detailed: Used to explicitly pull out information like the title. If not passed, the properties like the title value will be null.
  • IncludeOneDriveSites: Includes one drive sites in the result.
  • Force: Used to get the site collection results without any prompts. 
The following code snippet helps to retrieve all the site collections from the O365 SharePoint tenant site:
  1. $sites = Get-SPOTenantSite -Detailed -IncludeOneDriveSites -Force  
  2. Write-Host "There are " $sites.count " site collections present"  
  3. foreach($site in $sites){  
  4.     Write-Host "Title       : " $site.Title  
  5.     Write-Host "URL         : " $site.Url  
  6.     Write-Host "Template    : " $site.Template  
  7.     Write-Host "Status      : " $site.Status  
  8.     Write-Host "Storage (MB): " $site.StorageMaximumLevel  
  9.     Write-Host "Used (MB)   : " $site.StorageUsage  
  10.     Write-Host "Resources   : " $site.UserCodeMaximumLevel  
  11.     Write-Host "Owner       : " $site.Owner          
  12.     Write-Host "Sharing     : " $site.SharingCapability  
  13.     Write-Host "subsites    : " $site.WebsCount  
  14.     Write-Host "-----------------------------------------"    
  15. }  
The URL parameter is additionally used to get the information about the particular site collection. In the URL parameter, the site collection URL is passed to get the required information.
  1. $site = Get-SPOTenantSite -Url "https://abc.sharepoint.com/" -Detailed  
  2. Write-Host "Title       : " $site.Title  
  3. Write-Host "URL         : " $site.Url  
  4. Write-Host "Template    : " $site.Template  
  5. Write-Host "Status      : " $site.Status  
  6. Write-Host "Storage (MB): " $site.StorageMaximumLevel  
  7. Write-Host "Used (MB)   : " $site.StorageUsage  
  8. Write-Host "RESOURCES   : " $site.UserCodeMaximumLevel  
  9. Write-Host "Owner       : " $site.Owner          
  10. Write-Host "Sharing     : " $site.SharingCapability  
  11. Write-Host "subsites    : " $site.WebsCount  
  12. Write-Host "-----------------------------------------"  

Create Site Collection:

New-SPOTenantSite command is used to create the site collections on O365 SharePoint tenant.
The necessary parameters to create the site collections are:
  • Title
  • URL - New site collection full URL
  • Description
  • Template – site template Id
  • Resource quota – Number of the resources
  • Storage quota – Storage limit
  • Owner – Owner user Id
  • Time zone – Time zone number, which can be retrieved, using Get-SPOTimeZoneId command. 
The following code snippet helps to create a new site collection with the necessary parameters. The new site collection URL is passed.
  1. New-SPOTenantSite -Title "Test" -Url "https://abc.sharepoint.com/sites/Test" -Description "TestDesc" -Template "STS#0" -ResourceQuota 2 -StorageQuota 30 -Owner "abc@abc.onmicrosoft.com" -TimeZone 13  

Update Site Collection:

Set-SPOTenantSite is used to update the site collections present in the tenant site. The required parameter for the update is the site collection URL. The parameters like title, sharing and storage values can be updated.
The following code snippet helps to update the existing site collection with the necessary parameters. The existing site collection URL is passed.
  1. Set-SPOTenantSite -Url "https://abc.sharepoint.com/sites/Test" -Title "TestUpdated" -Sharing ExistingExternalUserSharingOnly  

Delete Site Collection:

Remove-SPOTenantSite command is used to delete a site collection. The required parameter for the delete operation is the existing site collection URL.
The following code snippet helps to remove a site collection from the O365 tenant. The site will be moved to the recycle bin.
  1. Remove-SPOTenantSite -Url "https://abc.sharepoint.com/sites/Test"  
The following code snippet helps to remove the site collection from the O365 tenant permanently.
  1. Remove-SPOTenantSite -Url "https://abc.sharepoint.com/sites/Test" -SkipRecycleBin -Force  

Summary:

Thus, you have learned how to create, retrieve, update or delete the site collections on Office 365 tenant/admin sites, using PnP PowerShell.

Create, Retrieve Or Delete Site Content Type On SharePoint Using PnP PowerShell

Views
In this post, you will learn, how we can create, retrieve and delete the site content types on SharePoint sites, using PnP PowerShell. The Client Side Object Model is used internally for these operations. The update operation is not available for the content types.

Prerequisite:

You need to have PowerShell 3.0, available on a Windows machine. You need to install or import PnP PowerShell packages. You can download the installers or view more documentation on the official site. The installers are available here.

The following operations will be compatible with SharePoint 2013 on-premise or Office 365 versions. 

Connect To Site:

Connect to the site, using the snippet, given below. The PnP PowerShell code, given below, helps in getting the current context of the site, using the Client Side Object Model (CSOM).
  1. #Get Current Context Site (Root)  
  2. $siteurl = "https://abc.sharepoint.com"  
  3. Connect-SPOnline -Url $siteurl  
  4. $ctx = Get-SPOContext  
Once connected, you can carry out any of the operations mentioned below, based on the requirement.

Create Site Content Type:

The content types can be added to the site collections by setting the context, using the site URL. PnP CSOM PowerShell can be used to complete the operation.

Add-SPOContentType command is used to create the site content types on SharePoint sites. The required parameters to create the new site content type are name, description and group. The new values can be passed as the parameters. In my example, I have created new site content called "PnPContentType". The default parent content type will be the item.

The following command snippet helps to create the new content type.
  1. function AddContentType(){  
  2.     Add-SPOContentType -Name "PnPContentType" -Description "PnP Content Type" -Group "PnPContentTypeGroup"  
  3. }  
  4. AddContentType # Create New Content Type with name, description  
The parent content type can be used as a base content type to create the new content types. The following example shows to create the  new content type, using the page content type, given below:
  1. function AddContentTypeUsingCT(){  
  2.     $pageCT = Get-SPOContentType -Identity Page  
  3.     Add-SPOContentType -Name "PnPPageContentType" -Description "PnP Content Type" -Group "PnPContentTypeGroup" -ParentContentType $pageCT  
  4. }  
  5. AddContentTypeUsingCT # Create New Content Type with name, description using page content type  
The following snapshot shows the new content types added to the site.


Retrieve Site Content Type:

The content types available on the site can be retrieved by setting the content with the URL, using PnP PowerShell. The following snapshot shows retrieval of all the content types from the site:
  1. function RetrieveContentTypes(){  
  2.     Get-SPOContentType        
  3. }  
  4. RetrieveContentTypes # Retrieves all the content types from site level  
The content type can be retrieved, using the content type Id.
  1. function RetrieveContentTypeByName(){  
  2.     Get-SPOContentType -Identity "Item"  
  3. }  
  4. RetrieveContentTypeByName # Retrieves the content type from site using name  
The following snapshot shows the content type retrieval, using PnP command:


The content type can be retrieved using, the content type name.
  1. function RetrieveContentTypeById(){  
  2.     Get-SPOContentType -Identity 0x01  
  3. }  
  4. RetrieveContentTypeById # Retrieves the content type from site using id  
The site content types from the particular list can be retrieved, using the list name.
  1. function RetrieveSiteCTfromList(){  
  2.     Get-SPOContentType -List "PnPList"  
  3. }  
  4. RetrieveSiteCTfromList # Retrieves the site content type from particular list  

Delete Site Content Type:

The site content type can be deleted from SharePoint site, using PnP PowerShell. Remove-SPOContentType is used to delete the content types. The content type name is passed for deleting the content type. The name or ID can be passed with the command, using the identity parameter.
  1. function RemoveContentType(){  
  2.     Remove-SPOContentType -Identity "PnPContentType" –Force  
  3. }  
  4. RemoveContentType # Delete the content type from site using name