Skip to content

Instantly share code, notes, and snippets.

View ktskumar's full-sized avatar

Shantha Kumar T ktskumar

View GitHub Profile
@ktskumar
ktskumar / updateWriteSecurity.js
Created November 30, 2021 07:19
Change Item Level permission for SitePages Library
//Update the WriteSecurity to change the item level permissions
//Set the Edit property to Create items and edit items that were created by the user
// 1 - Create and edit all items
// 2 - Create items and edit items that were created by the user
// 3 - None
import { sp, Web } from "@pnp/sp/presets/all";
(async () => {
@ktskumar
ktskumar / spfx-mgt-showemails.htm
Created November 30, 2021 00:46
Display Recent Mails using Microsoft Graph Toolkit
<mgt-get resource="/me/messages" version="beta" scopes="mail.read" max-pages="2">
<template>
<div style="background-color:#eee;padding:8px 30px;">
<div class="email" data-for="email in value" style="padding:20px; background-color:#fff">
<h3>{{ email.subject }}</h3>
<h4>
<mgt-person person-query="{{email.sender.emailAddress.address}}" view="oneline" person-card="hover">
</mgt-person>
</h4>
<div data-if="email.bodyPreview" class="preview" innerHtml>{{email.bodyPreview}}</div>
@ktskumar
ktskumar / spHideSearchBoxinNavBar.js
Created June 17, 2021 18:02
Code helps to hide the searchbox in navbar in SharePoint Site
// POST request Call
function RestRequest(url, params) {
var req = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState != 4) // Loaded
return;
if (req.status >= 200 && req.status < 300) {
resolve(req);
} else {
@ktskumar
ktskumar / exportnobirthdayusers.ps1
Created June 12, 2021 16:57
Export all the users with no birthday value set in the Profile using Microsoft 365 CLI
$outputfilepath = "< OUTPUT PATH WITH FILENAME.csv >"
Write-host 'ensure logged in'
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
m365 login
}
# Fetch all AAD users from Microsoft 365
$allusers = m365 aad user list --properties 'displayName,userPrincipalName,accountEnabled' -o json | ConvertFrom-Json
@ktskumar
ktskumar / spfxmgt-showallapplications.html
Created June 9, 2021 11:32
Show all Application Registrations using Microsoft Graph Toolkit in a SharePoint Framework webpart
<!-- THIS CODE USES THE MICROSOFT GRAPH TOOLKIT -->
<!-- USE THE MICROSOFT GRAPH TOOLKIT EDITOR WEBPART FOR BETTER RESULT -->
<!-- REFERENCE LINK: http://www.ktskumar.com/2021/06/spfx-microsoft-graph-toolkit-show-all-application-registrations-in-sharepoint/ -->
<style type="text/css">
table {
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
@ktskumar
ktskumar / m365.exportallpagecontrols.ps1
Created June 7, 2021 15:54
Export all controls or webparts from all modern site pages in a site using Microsoft 365 CLI
#Export all webpart or control information from all pages in a SharePoint site to CSV format
###
$outputfilepath = "<Output fodler>\webparts.csv"
$weburl = "https://contoso.sharepoint.com"
#Validate login in
$m365Status = m365 status
if ($m365Status -eq "Logged Out") {
m365 login
}
@ktskumar
ktskumar / spPostRequest.js
Created June 6, 2021 05:39
HTTP Post request to be used with SharePoint Online REST API to do the post activities
// POST request Call
function RestRequest(url, params) {
var req = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState != 4) // Loaded
return;
if (req.status >= 200 && req.status < 300) {
resolve(req);
} else {
@ktskumar
ktskumar / SyncFlowInstances.js
Created June 6, 2021 05:29
Retrieves the Flow instances associated to the SharePoint List using REST API
/* **** RUN THIS SNIPPET in Browser Developer Console to see the output **** */
// POST request Call
function RestRequest(url, params) {
var req = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState != 4) // Loaded
return;
if (req.status >= 200 && req.status < 300) {
resolve(req);
@ktskumar
ktskumar / Syncflowtemplates.js
Created June 6, 2021 05:17
Retrieves the Flow templates associated to the SharePoint List using REST API
/* **** RUN THIS SNIPPET in Browser Developer Console to see the output **** */
// POST request Call
function RestRequest(url, params) {
var req = new XMLHttpRequest();
return new Promise(function(resolve, reject) {
req.onreadystatechange = function() {
if (req.readyState != 4) // Loaded
return;
if (req.status >= 200 && req.status < 300) {
resolve(req);
@ktskumar
ktskumar / exportflowrunhistories.ps1
Created June 5, 2021 06:10
Export all flow run histories from the Default Environment in Power Platform
Write-Host '****** Export All Flow run histories into CSV ******'
#Provide Ouput Folder Path
$outputPath = "<Output Folder Path>"
$timestamp = Get-Date -Format "yyyymmddhhmmss"
$flowhistoryValues = @()
$environmentId = $(m365 flow environment list --query "[?contains(name,'Default')]" -o json | ConvertFrom-Json).Name
$flows = m365 flow list --environment $environmentId -o json | ConvertFrom-Json