Wednesday, September 23, 2020

Azure Function Chaining - Get web Title in SharePoint Online

Visual Studio sample code

Here is the orchestration as a single C# file in a Visual Studio project:
using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; namespace VSSample { public static class HelloSequence { [FunctionName("E1_HelloSequence")] public static async Task<List<string>> Run( [OrchestrationTrigger] DurableOrchestrationContextBase context) { var outputs = new List<string>();
var SiteUrl="https://tenant.sharepoint.com/sites/TestSite";
outputs.Add(await context.CallActivityAsync<string>("E1_GetSiteTitle", SiteUrl)); return outputs; } [FunctionName("E1_GetSiteTitle")] public static string GetSiteTitle([ActivityTrigger] DurableActivityContextBase context)
        {
            string siteDescription = "this is communication site for test purpose";
            string siteUrl = "https://gidcmylan.sharepoint.com/sites/" + webTitle;
            string tenantURL = "https://gidcmylan-admin.sharepoint.com";
            string UName = "test@gidcmylan.onmicrosoft.com";
            string Password = "Mylan@123";
            string communityUrl = string.Empty;

            SecureString securePwd = new SecureString();
            foreach (char c in Password)
            {
                securePwd.AppendChar(c);
            }
            securePwd.MakeReadOnly();
            /* Create Site using CreateSiteAsync method */
            using (var ctx = new ClientContext(siteUrl))
            {
                // ctx.Credentials = new NetworkCredentials(userName, pwd);
                ctx.Credentials = new SharePointOnlineCredentials(UName, securePwd);
                ctx.RequestTimeout = Timeout.Infinite;

                // Just to output the site details
                Web web = ctx.Web;
                ctx.Load(web, w => w.Title);
                ctx.ExecuteQuery();
                communityUrl = "Web Title is :" + web.Title;
            }

            return $"Hello {communityUrl}!";
        }
} }

Console Application to Create new Subsite under site collection using CSOM + SharePoint Online

 using System;

using System.Security;

using Microsoft.SharePoint.Client;


namespace ConsoleAppCreateSubsite

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("Enter Your Username Please  ------- ");

            string userName = Console.ReadLine();

            //string userName = "girish.kumar@happiestbarik.onmicrosoft.com";

            Console.WriteLine("Enter Your Password Please  ------- ");

            SecureString password = GetPasswordOfYourSite();

            Console.WriteLine("Enter Your Site collection URL  ------- ");

            string SiteCollURL = Console.ReadLine();

            Console.WriteLine("Enter Your New Subsite URL name   ------- ");

            string newSubsiteName = Console.ReadLine();

            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();

            using (var clientContext = new

            ClientContext(SiteCollURL))

            {

                // SharePoint Online Credentials  

                clientContext.Credentials = new SharePointOnlineCredentials(userName, password);

                // Get the SharePoint web  

                WebCreationInformation creation = new WebCreationInformation();

                creation.Url = newSubsiteName; //"MyConsoleWeb";

                creation.Title = "WelcomeToConsoleWeb";

                Web newWeb = clientContext.Web.Webs.Add(creation);


                // Retrieve the new web information. 

                clientContext.Load(newWeb, w => w.Title);

                clientContext.ExecuteQuery();

                clientContext.ExecuteQuery();

            }


        }


        private static SecureString GetPasswordOfYourSite()

        {

            ConsoleKeyInfo info;

            //Get the user's password as a SecureString  

            SecureString securePassword = new SecureString();

            do

            {

                info = Console.ReadKey(true);

                if (info.Key != ConsoleKey.Enter)

                {

                    securePassword.AppendChar(info.KeyChar);

                }

            }

            while (info.Key != ConsoleKey.Enter);

            return securePassword;

        }

    }

}

Thursday, February 13, 2020

Powershell Script for add “everyone, except external users” to the visitors group

Dear Reader,

PS script to  add “everyone, except external users” to the visitors' group.

And finding the display name and login Name for users.

Just Replace Tenant name, organizations name, admin credentials

PS C:\WINDOWS\system32> $adminUPN="girishkumar@{Tenant}.onmicrosoft.com"

PS C:\WINDOWS\system32> $orgName="{Tenant name}"

PS C:\WINDOWS\system32> $userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."

PS C:\WINDOWS\system32> Connect-SPOService -Url https://$orgName-admin.sharepoint.com -Credential $userCredential

Get-SPOUser -Site https://$orgName.sharepoint.com/sites/SiteName | Select DisplayName, LoginName

PS C:\WINDOWS\system32> Add-SPOUser -Site https://$orgName.sharepoint.com/sites/Coronavirus -LoginName "c:0-.f|rolemanager|spo-grid-all-users/{GUID}" -Group "Site Visitors"

Display Name                   Login Name                                              Groups                 User Type
------------                   ----------                                              ------                 ---------
Everyone except external users spo-grid-all-users/{GUID} {Site Visitors} Member


All the Best! Thanks for reading my blog, please do comment and share if you feel helpful.


Kind Regards,

Girish Kumar M S

Update or edit status filed in JIRA issue

the status field is a special case and can't be updated directly, which is the second problem here. Changing a status in Jira is called ...