Wildcard SSL for SP and high-trust-certificate

I. Follow this to create a new certificate using for SSL:



$cert = New-SelfSignedCertificate -DnsName “*.spdev.com” -CertStoreLocation “cert:\LocalMachine\My”

Then, go to iss web application -> bindings -> edit -> https -> SSL certificate: *.spdev.com -> host name: http://www.spdev.com -> port 443

launch the web application, on address bar, click to install the certificate to the computer

II. Follow this to create a new certificate for SP high trusted app:



  1. Create a self-sign-certificate
  2. Export to pfx
  3. Export to cer
  4. Open MMC, install certificate to “Trusted Root Certificate Authority” and “Personal”
  5. On Personal, right click to the certificate -> All Tasks -> Manage Private Keys…-> Add user in your wep application pool to here
  6. Share certificate folder to everyone
  7. ……………………
  8. New-SPTrustedRootAuthority (remove first if already existed)
  9. New-SPTrustedSecurityTokenIssuer (remove first if already existed)
  10. AllowOAuthOverHttp
  11. Update OnPrem.config for all web applications
  12. IIS reset all



Get User Profile Properties with REST API

Thanks Vardhaman Deshpande for this tips:

1) Get all properties of current user:


2) Get single property of current user:


3) Get Multiple Properties for the current user:


4) Get all properties of Specific User:

For Office 365/SharePoint Online:

For SharePoint 2013 On-Premises:

5) Get Specific UserProfile Property of Specific User:

For Office 365/SharePoint Online:

For SharePoint 2013 On-Premises:

6) Get Multiple UserProfile Properties for Specific User:


Script to activate SharePoint feature on all site collection – Combine PnP and CSOM scripts

The prerequisite for this script is you need to be global admin on your tenant or you you have app installed with full permission on tenant scope

Let’s assume that your app have full permission on tenant scope, and you know the client id/client secret of your app

1. If your powersell script is not support for the execution policy, add this to your powershell windows first:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

2. Import SharePointPnPPowerShellOnline and Microsoft.Online.SharePoint.Powershell

Import-Module SharePointPnPPowerShellOnline -Scope “Local”
Import-Module Microsoft.Online.SharePoint.Powershell

Add-Type -Path “$path to client dlls\Microsoft.SharePoint.Client.dll”
Add-Type -Path “$path to client dlls\Microsoft.SharePoint.Client.Runtime.dll”

3. Declare the parameters

$global:appId = “your-client-id-guid-string”
$global:appSecret = “your-client-secret”

$global:adminUrl = “https://yoursharepoint-admin.sharepoint.com”

$global:SPFeatureId = “any-sharepoint-feature-id-fbace37b4a34”;

4. Connect to admin URL to get all site collection

Connect-PnPOnline -AppId $global:appId -AppSecret $global:appSecret -Url $global:adminUrl

$adminConnection = Get-PnPConnection

$allSitecollections = Get-PnPTenantSite -Connection $adminConnection

$sitecollections = New-Object System.Collections.ArrayList

5. For each site collection, connect again and activate the feature

foreach($siteCollection in $allSitecollections)
$targetUrl = $siteCollection.Url
Connect-PnPOnline -AppId $global:appId -AppSecret $global:appSecret -Url $targetUrl
$connection = Get-PnPConnection

#Activate SPFeature
$ctx = Get-PnPContext #This is important to get client content and use in CSOM
$site = $ctx.site

$Site.Features.Add($global:SPFeatureId, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | Out-Null

Disconnect-PnPOnline -ErrorAction SilentlyContinue

That’s all!!!

Add a custom javascript file to SharePoint library using csom

var list = Ctx.Site.GetCatalog((int)ListTemplateType.MasterPageCatalog);

var rootFolder = list.RootFolder;

bool displayTemplateExists = DisplayTemplateExists(Ctx, list, ProjectStatusAll.Title);
string destFileName = rootFolder.ServerRelativeUrl + “/Display Templates/Content Web Parts/” + “Item_ProjectStatusAll.js”;
string content = ProjectStatusAll.Content;
string ctId = “0x0101002039C03B61C64EC4A04F5361F38510660500E478F12A266BD24B842D0B2128BDDAAB”;

var fields = new List<KeyValuePair<string, string>>();

fields.Add(new KeyValuePair<string, string>(“Title”, ProjectStatusAll.Title));
fields.Add(new KeyValuePair<string, string>(“TargetControlType”, ProjectStatusAll.TargetControlType));
fields.Add(new KeyValuePair<string, string>(“DisplayTemplateLevel”, ProjectStatusAll.DisplayTemplateLevel));
fields.Add(new KeyValuePair<string, string>(“TemplateHidden”, ProjectStatusAll.TemplateHidden));
fields.Add(new KeyValuePair<string, string>(“ManagedPropertyMapping”, ProjectStatusAll.ManagedPropertyMapping));

if (!displayTemplateExists)
CreateFile(Ctx, list, content, Encoding.UTF8, destFileName, ctId, fields, false);


public File CreateFile(ClientContext Ctx, List list, string content, Encoding encoding, string destFileName, string ctId, List<KeyValuePair<string, string>> fields, bool overwrite)
// Verify encoding
if (encoding == null)
throw new ArgumentNullException(“encoding”);

if (list == null)
throw new ArgumentNullException(“list”);

FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = destFileName;
fileCreateInfo.Content = encoding.GetBytes(content);
fileCreateInfo.Overwrite = overwrite;

File createdFile = list.RootFolder.Files.Add(fileCreateInfo);

ListItem item = createdFile.ListItemAllFields;

item[“ContentTypeId”] = ctId;

foreach (var field in fields)
item[field.Key] = field.Value;


return createdFile;

PnP Tools for SharePoint Modernization scanner + GetWebLoginClientContext


$authenticationManagerSiteScope = New-Object -TypeName OfficeDevPnP.Core.AuthenticationManager






Get SharePoint site/subsites template using javascript

var siteCollections = [

siteCollections.forEach(function (site) {
var webCollection = null;
function getWebTemplate() {
var context = new SP.ClientContext(site);
//var context = SP.ClientContext.get_current();
var web = context.get_web();
function () {
var webTemplate = web.get_webTemplate();
var configuration = web.get_configuration();

var templateName = webTemplate + “#” + configuration;
var isTeamSite = templateName === “STS#0”;

console.log(site + “,” + templateName + “,,” + (isTeamSite? “Classic Team Site”: “”));

url: site + “/_api/web/webs/?$select=title,ServerRelativeUrl,Created,webTemplate,configuration”,
method: “GET”,
headers: {
“Accept”: “application/json; odata=verbose”
success: function (data) {
$.each(data.d.results, function (index, item) {
templateName = item.WebTemplate + “#” + (item.Configuration + 1);
isTeamSite = templateName === “STS#0”;

console.log(site + item.ServerRelativeUrl + “,” + templateName + “,,” + (isTeamSite ? “Classic Team Site” : “”));
error: function (data) {
//console.log(site + “,,Unable to get sub sites”);

function (sender, args) {
//console.log(site + “,,Unable to check the site template”);

Work with Datetime RegionalSettings in SharePoint


Greenwich Mean Time or GMT is the clock time at the Royal Observatory in Greenwich, London. It is the same all year round and is not affected by Summer Time or Daylight Saving Time.

UTC – The World’s Time Standard – Coordinated Universal Time (UTC) is the basis for civil time today. This 24-hour time standard is kept using highly precise atomic clocks combined with the Earth’s rotation.

Day Light Saving Time (DST) on the other hand is advancing clocks To and for with season changes, To make max use of day light.


var siteTimeZone = Ctx.Web.RegionalSettings.TimeZone;

TimeZoneInfo timeZoneInfo = GetTimeZoneInfo(siteTimeZone);
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZoneInfo);

public TimeZoneInfo GetTimeZoneInfo(Microsoft.SharePoint.Client.TimeZone timezone)
TimeZoneInfo webTimezoneInfo;
string timezoneInfoId = GetTimezoneInfoIdBySiteTimezoneId(timezone.Id);
if (timezoneInfoId == “”){
webTimezoneInfo = null;}
webTimezoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezoneInfoId);}

return webTimezoneInfo;

public static string GetTimezoneInfoIdBySiteTimezoneId(int id)
switch (id)
case 86:
return “Morocco Standard Time”;
case 2:
return “GMT Standard Time”;
case 93:
return “UTC”;
case 31:
return “Greenwich Standard Time”;
case 4:
return “W. Europe Standard Time”;
case 6:
return “Central Europe Standard Time”;
case 3:
return “Romance Standard Time”;
case 57:
return “Central European Standard Time”;
case 69:
return “W. Central Africa Standard Time”;
case 79:
return “Jordan Standard Time”;
case 5:
case 101:
return “GTB Standard Time”;
case 80:
case 98:
return “Middle East Standard Time”;
case 49:
return “Egypt Standard Time”;
case 50:
return “South Africa Standard Time”;
case 59:
return “FLE Standard Time”;
case 27:
return “Israel Standard Time”;
case 7:
return “E. Europe Standard Time”;
case 26:
return “Arabic Standard Time”;
case 74:
return “Arab Standard Time”;
case 51:
return “Russian Standard Time”;
case 56:
return “E. Africa Standard Time”;
case 25:
return “Iran Standard Time”;
case 82:
return “Georgian Standard Time”;
case 24:
return “Arabian Standard Time”;
case 54:
return “Azerbaijan Standard Time”;
case 89:
return “Mauritius Standard Time”;
case 84:
return “Caucasus Standard Time”;
case 48:
return “Afghanistan Standard Time”;
case 58:
return “Ekaterinburg Standard Time”;
case 87:
return “Pakistan Standard Time”;
case 47:
return “West Asia Standard Time”;
case 23:
return “India Standard Time”;
case 66:
return “Sri Lanka Standard Time”;
case 62:
return “Nepal Standard Time”;
case 46:
return “N. Central Asia Standard Time”;
case 71:
return “Central Asia Standard Time”;
case 61:
return “Myanmar Standard Time”;
case 22:
return “SE Asia Standard Time”;
case 64:
return “North Asia Standard Time”;
case 45:
return “China Standard Time”;
case 63:
return “North Asia East Standard Time”;
case 21:
return “Singapore Standard Time”;
case 73:
return “W. Australia Standard Time”;
case 75:
return “Taipei Standard Time”;
case 20:
return “Tokyo Standard Time”;
case 72:
return “Korea Standard Time”;
case 70:
return “Yakutsk Standard Time”;
case 19:
return “Cen. Australia Standard Time”;
case 44:
return “AUS Central Standard Time”;
case 18:
return “E. Australia Standard Time”;
case 76:
return “AUS Eastern Standard Time”;
case 43:
return “West Pacific Standard Time”;
case 42:
return “Tasmania Standard Time”;
case 68:
return “Vladivostok Standard Time”;
case 41:
return “Central Pacific Standard Time”;
case 17:
return “New Zealand Standard Time”;
case 40:
case 92:
return “Fiji Standard Time”;
case 67:
case 16:
return “Tonga Standard Time”;
case 29:
return “Azores Standard Time”;
case 53:
return “Cape Verde Standard Time”;
case 30:
return “Mid-Atlantic Standard Time”;
case 8:
return “E. South America Standard Time”;
case 85:
return “Argentina Standard Time”;
case 60:
return “Greenland Standard Time”;
case 90:
return “Montevideo Standard Time”;
case 28:
return “Newfoundland Standard Time”;
case 9:
return “Atlantic Standard Time”;
case 33:
return “Central Brazilian Standard Time”;
case 65:
case 91:
return “Pacific SA Standard Time”;
case 88:
return “Venezuela Standard Time”;
case 35:
return “SA Pacific Standard Time”;
case 10:
return “Eastern Standard Time”;
case 34:
return “US Eastern Standard Time”;
case 55:
return “Central America Standard Time”;
case 11:
return “Central Standard Time”;
case 37:
return “Central Standard Time (Mexico)”;
case 36:
return “Canada Central Standard Time”;
case 38:
return “US Mountain Standard Time”;
case 77:
return “Mountain Standard Time (Mexico)”;
case 12:
return “Mountain Standard Time”;
case 13:
return “Pacific Standard Time”;
case 78:
return “Pacific Standard Time (Mexico)”;
case 14:
return “Alaskan Standard Time”;
case 15:
return “Hawaiian Standard Time”;
case 39:
return “Dateline Standard Time”;
return “”;


private convertFromLocalTimeToGMT0 = (eventPage: Models.IEventPage) => {
var obj = {};

var executor: Models.IExecutor = (resolve, reject) => {
this.getTimeZoneInformation().then((tzInformation) => {
var timeZoneInformation = tzInformation.Information;
var hourDiff = timeZoneInformation.Bias / 60;
var timeDiff = hourDiff * 60 * 60 * 1000;

var startDate = new Date(eventPage.startDate);

var siteStartDateAsGMT0 = startDate.setTime(startDate.getTime() + timeDiff);

var startDateWithoutUTC = this.convertDateTimeToStringWithoutUTC(new Date(siteStartDateAsGMT0));

obj[Constants.SharePoint.Fields.START_DATE] = startDateWithoutUTC;


return new Promise(executor);

public getDateTimeSiteRegionalSettings = (localDateTime: string) => {
var siteUrl = this.getCurrentSiteUrl();
var executor: Models.IExecutor = (resolve, reject) => {
url: siteUrl + “/_api/web/RegionalSettings/TimeZone/utcToLocalTime(@date)?       @date='” + new Date(localDateTime).toUTCString() + “‘”,
method: “GET”,
headers: { “Accept”: “application/json; odata=verbose” },
success: (data) => {
var newValue = this.parseDate(data.d.UTCToLocalTime);
error: () => {

return new Promise(executor);

private getTimeZoneInformation = () => {
var siteUrl = this.getCurrentSiteUrl();
var executor: Models.IExecutor = (resolve, reject) => {
url: siteUrl + “/_api/web/RegionalSettings/TimeZone”,
method: “GET”,
headers: { “Accept”: “application/json; odata=verbose” },
success: (data) => {
error: () => {

return new Promise(executor);

private convertDateTimeToStringWithoutUTC = (dateTime?: Date) => {
return Utils.isNullOrEmpty(dateTime) ? null : dateTime.format(“yyyy-MM-ddTHH:mm:ss”);