Monday 10 December 2018

Archived and Restore teams in Microsoft Teams using PowerShell without user credentials

Problem Statement : As we are aware recently Microsoft has introduced a feature in Teams that Owner of the site can Archive and restore the teams using a few clicks. Though we want to Automate this process using PowerShell with Task scheduler so no manual intervention required.

Solution:  We have developed a PowerShell solution from which we find Inactivity of teams in the last 60 days based on Email ,chat and File Accessed with associated team site. if Powershell script running on Task Scheduler find the teams is inactive for 60 days it Archive the Teams. Archival of the site is not available with Powershell command yet but MS has made available using Graph API.

Step 1: Access Graph API using Powershell

Once you followed the Above Article you should be able to Know the APP ID, App Secret and AADDomain.

Step 2 :Provide Admin consent for this newly created App 

form the URL as below and paste in your broswer.{Yourtenant}/adminconsent?client_id={YourAPPIID}&state=12345&redirect_uri={YourAppRedirectURL}

You need to be part of Administrator, once you given the Admin consent will be able to get Access token using this App for Graph API

Step 3: once you get the Access token its very easy to do the Archival of Team pf Restore.

Please follow the below code.

Connect-PnPOnline -AppId 'YourAppID' -AppSecret 'Your App Secret ID' -AADDomain ''

# Get token to connect the Graph API
 $token = Get-PnPAccessToken

 $headers = @{"Content-Type" = "application/json" ;           "Authorization" = "Bearer " + $token}
For Archive below is the URL formation

$SecScoreURI = ""+YourTeamGroupID+"/archive"

For Restore below is the URL formation  

$SecScoreURI = ""+YourTeamGroupID+"/unarchive"

#Execute the Graph API
$output = Invoke-RestMethod -Uri $SecScoreURI -Headers $headers -Method POST  

And boom your Teams Archive and UnArchive will be done using PowerShell. Getting the Group ID is very easy if you are team Owners.

 Note - you need to be Owner of the teams

let me know if any issue faced

Tuesday 14 August 2018

Schedule Publishing of Modern Site Pages in Sharepoint online Office 365

Problem Statement : As we are aware we don't have any Schedule Publishing features for Modern SharePoint Pages. Still user wanted to have scheduled Publishing of News Article.

Solution:  We have created a custom Column Property name called PublishDate for Site Pages Library as below screen shot.

Schedule Publishing of Modern Site Pages in Sharepoint online Office 365

we have asked News Publishers to follow the below steps for Schedule Publishing if they want to do.

Step 1 : Create a Site page

Step 2 :  Edit the content as they wanted

Step 3 :  save the article as draft

Step 4 :  edit the site page properties and update the Column "PublishDate" with their desired date and Time of the Publishing as shown in above pic.

Task Scheduler : we run a scheduler at every 15 min to check whether any Saved Draft article or News is available for Publishing. scheduler run a Powershell script as below.

# A script to check for all draft site pages where Published date is non empty
# we will publish those pages and promote as new article

# Created 26-June-2018  vinit kumar

# Check that we are connected to sharepoint Online

$Password = ConvertTo-SecureString  "Password" -AsPlainText -Force

$SiteListName="Site Pages"

$SPCredentials = New-Object -typename System.Management.Automation.PSCredential -argumentlist $UserName,$Password

$currentDate +"-:Connect Start" | out-File $Logpath -Append
Connect-PnPOnline -Url $URL -Credentials $SPCredentials
$currentDate +"-:Connect Ends" | out-File $Logpath -Append

$getdraftItems = Get-PnPListItem -List $SiteListName  -Query "
                <FieldRef Name='_ModerationStatus'/>
               <Value Type='ModStat'>Draft</Value>
            <FieldRef Name='PublishDate'/>

$currentDate +"-:Query Call Success" | out-File $Logpath -Append
ForEach ($item in $getdraftItems) {
if( $item.FieldValues.PublishDate -le  $curretDateandTime){
 Set-PnPClientSidePage  -Identity $FileName -Publish -PromoteAs NewsArticle
 $currentDate +"-:Success Promoting the Page "+$FileName | out-File $Logpath -Append
  $currentDate +"-:Error Promoting the Page "+$FileName | out-File $Logpath -Append

Script check if article Moderation Status  is "Draft" and Current Date and Time is greater than the Published date then using Modern Client side page script first we publish the Article and then Promote as News.

This is a workaround since scehdule Publishing is not available currently but might available in future.

If you like you can use this solution or share.

Happy Modern site 

Monday 21 May 2018

How to Make a SharePoint term unavailable for Tagging/List usage but available in Search Result

Problem Statement : Recently i got a requirement from Business that they do not want one of their Market region area (Term Sets) to be displayed for user selection while submitting a SharePoint List form but previous data with that region should be available for Search.

Solution :

Regions are stored in term store as below Image and available for Tagging in SharePoint List.

User can select these region and use for the any custom list or Document Library for Tagging purpose. below is the employee region mapping where I have utilized above region temsets.

After crawling of this list data we can search "Europe" and get result item as below

Now we have requirement like "Europe" keyword should be searchable but no other item can be added with "Europe" term.

Solution Tip : if we deprecate a Term in Termset then it will be available for search and refiners but will not be available for New item addition.

lets deprecate the term, who already know how to deprecate a Term no need to look below to my blog. You people can jump to your next task.

Steps to disable the  term:

1. Go to Termstore
2. Find your Termset
3. Right click on the term which you want to deprecate (as below screenshot)

now we will check whether "Europe" is still available for tagging or not. below screenshot confirms that "Europe" is no more available for tagging in the list.

but previously added item with "Europe" should be still searchable as like below screenshot.

Most of the big SharePoint developers already might know, but may be helpful for someone.

Happy Office365