Pages

PowerShell for SharePoint

SharePoint has been introduced since a long ago and has evolved over time. This post attempts to gather different methods of interacting SharePoint with PowerShell.

SharePoint Management Shell

There are two SharePoint Mangement Shell PowerShell modules. One for SharePoint online and another one for SharePoint Server.

SharePoint Online

This is a Windows PowerShell module to manage SharePoint Settings for organization or site collection level. Useful for SharePoint administrator and site admin. The module is Microsoft.Online.SharePoint.PowerShell and the command naming convention starts with SPO as its noun, as example
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser
Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential admin@contoso.com
List of SharePoint Online PowerShell commands and its documentation

SharePoint Server

The PowerShell cmdlets comes along with SharePoint Server installation. Useful for SharePoint administrator. To use the SharePoint cmdlets (provided as snap-in, not module) in Windows PowerShell, register the snap-in manually, Add-PSSnapin Microsoft.SharePoint.PowerShell. If it is executed from SharePoint Managemetn Shell, it is automatically registered. Command naming convention usually starts with SP as its noun, as example
Add-PSSnapin Microsoft.SharePoint.PowerShell
Get-SPSite
List of SharePoint Server PowerShell commands and its documentation

PnP PowerShell

This is a PowerShell module with more than 600 commands to interact with SharepPoint Online, Microsoft Teams, Microsoft Entra ID, and etc. It is an open source and community provided library under Microsoft 365 platform community initiative. This module is useful for various team including SharePoint admnistrator, developer, power user and etc. The module is PnP.PowerShell and the command naming convention starts with PnP, as example
Install-Module PnP.PowerShell -Scope CurrentUser
Connect-PnPOnline
List of PnP PowerShell commands and its documentation

Microsoft Graph PowerShell

This is a PowerShell module (recommended PowerShell core, can be used in Windows PowerShell) that acting as API wrapper for Microsoft Graph APIs. Microsoft Graph API cover various aspects from Azure Entra ID, to other Microsoft services like SharePoint, Exchange, Outlook and etc. This module is useful for SharePoint admin, developer and power user. The main module is Microsoft.Graph and for SharePoint specific submodule is Microsoft.Graph.Sites. The command naming convention starts with Mg, as example
Install-Module Microsoft.Graph -Scope CurrentUser 
Connect-MgGraph
List of SharePoint command in Microsoft Graph and its documentation

PowerShell with CSOM / API

SharePoint .NET client-side object model (CSOM) and REST API could be used in PowerShell as .NET object or wrapped as PowerShell command

The CSOM are available to download via SharePoint Online Client Component SDK or SharePoint .NET nuget package.

as example to add/use CSOM (after the CSOM dll been downloaded and location the identified)
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($WebUrl) 
SharePoint REST API V1 (documentation)
SharePoint REST API V2 (documentation)
SharePoint Sites Microsoft Graph REST API (documentation)

Microsoft Certified

It has been a while since I last pursued a Microsoft certification.

After a few years working as a developer, I focused primarily on SQL Server data platform and business intelligence. I learned from work experiences, Microsoft articles as well as various blogs from the awesome SQL Server communities. To test my level of knowledge and exposure in this field, I also took the challenge of certification for Microsoft Certified Solution Expert for Data Platform and Business Intelligence.

As my role at work continue to evolve, I have been wearing multiple hats and at time switch hat. I found myself heavily involved in Azure AD, Okta, Azure cloud resources, Azure Devops, Github, App / API Gateway, etc.. in addition to SQL Server administration.

Access Office 365 Exchange Online Mailbox with Client Credential Flow

As of this writing, Microsoft has disabled the basic authentication to Exchange Online, the alternate more secure method to authenticate and access Exchange Online is via Client Credential flow using OAuth token. OAuth (OIDC) Client Credential flow is typically used for background (eg. windows services or daemon) process without interaction with user.

Microsoft provides different APIs to access Exchange Online. To authenticate against these APIs, we need OAuth access token with appropriate permissions when invoking these APIs. And this type of access token is obtained from Azure AD.

GitHub Create Private Fork of a Public Repository

When making a fork of a GitHub public repository, the fork repository is set up with public visibility. However, under certain circumstances, it may be desirable to make the fork repository with private or internal (in an organization) visibility.

Here is one way to indirectly 'forking' a repository with with private or internal visibility.


Create Sharepoint Site with Azure Function using PowerShell

Business Case
Create SharePoint site based on user requirement without SharePoint Admin manually performing the task.

Design
A SharePoint List is created and shared with designated users to enter the desired SharePoint site criteria. Using an Azure function with PnP PowerShell module (compatible with PowerShell core in Azure function) to periodically check if any new entry in the SharePoint List and create SharePoint site based on the user entered criteria.



Network Traffic Capture Without Installing Any Software



From time to time, there is a need to capture network traffic for troubleshooting on server. Some network tool like Wireshark is pretty popular for network capturing. However, these tool often need additional installation on the server, and depending on your security team rules, it may take days to be installed on the server.

There is an alternate way to capture network traffic on Windows OS without additional software installation. Using Netsh trace. Most of you may familiar with Netsh for different type of common purpose like firewall, http listener, network interface info, etc. Netsh could be also used to collect network trace.

Inserting and Hosting 551 Millions Records Cheaply - Case Study



Recently I worked on a pet project with cloud implementation. There was a dump file in text format with 551 million line of records which needs to be stored in a way where filtered results could be quickly returned from a query, and with a goal of low cost implementation.

The dataset is static. Large number of records. No relational requirement. The storage and querying has to be fast and low cost. Azure table storage seems to be a good candidate for this purpose. Azure table storage is a NoSQL key value store and is very cheap.

Windows Guy Learning Linux - Basic Command for Linux

If you have been working mostly with Microsoft technology stacks, switching from Windows and learning Linux could be an exciting and daunting journey. So far my journey to Linux has been fun and I love it!

Linux has GUI but mostly (almost entirely) for server and application administration are performed using command line. If you are on Windows workstation, PuTTY software could be used to ssh into Linux server.

Microsoft Recertification

Year 2016 is just around the corner. People are in holiday mood and in fact a lot of folks are on vacation at this time around. Project usually take this slow period into account and avoid any heavy personnel involvement and introduce changes only where necessary. This slow time of the year could be a great opportunity to expand knowledge and skills, and possibly look into certification / recertification.

SQL Replication - Subscriber On Different Domain

Setting up SQL Server replication with publisher / distributor on one domain and subscriber on another domain could be tricky. It could be even more interesting when these servers have the same host name. This blog post discuss issues encountered and the steps of addressing them.