Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Wednesday 20 December 2023

SharePoint site theme: Add a custom theme using PowerShell

In this blog, we will be learning how to create a custom theme for SharePoint Online.

Now SharePoint has a Site theming feature for applying custom styles and colors to the site. There are six light and two dark themes available by default. This feature provides the ability to define custom themes and make them available to site owners. Creating a custom theme in SharePoint is a quick and easy way to give your site a unique look and feel.

Currently, no theme is available under the "From your organization" option.


The steps to add a custom theme to SharePoint Online.

Step 1: Create a new color theme in SharePoint Online.

Themes are defined in a JSON schema that stores color settings and related metadata for each theme. Create a new custom theme for SharePoint Online using Microsoft Fluent UI Theme Designer, an online tool. Customize the theme as per your needs and click on the Export theme button. Copy and save the PowerShell output for later use.

Light Theme sample:


Dark Theme sample:


Step 2: Add a custom theme to SharePoint Online using PowerShell

First, connect to the SPO admin site using the Connect-SPOService cmdlet. The custom theme can be added to the SharePoint online tenant using the Add-SPOTheme cmdlet. This cmdlet creates a new theme or updates an existing theme. The color palette settings can be passed as either a hash table or a dictionary.

Execute the command for the light theme.



Now go to Site Settings, gear icon (⚙️) > Change the look > Theme and you'll find the newly added color theme listed under "From your organization".


Execute the same command for the dark theme.


Again, go to Site Settings gear icon (⚙️) > Change the look > Theme and you'll find the new added color theme listed under "From your organization".


When you choose a theme, color settings are instantly applied to the site so that you can see what the selected theme will look like. Select the desired theme, click Save to save your selection, or choose Cancel to revert to your current theme.

Our "Maroon - Light theme" output looks like




Our "Orange - Dark theme" output looks like




Update SP Theme
To update an existing theme (to modify some of its color settings, for example), add the -Overwrite flag to the Add-SPOTheme cmdlet.


I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€

Wednesday 6 December 2023

Create List templates using Site template and Site script

In this blog, we will be learning how to create list templates under the tab From your organization.

When people in the organization create new lists, they need a template that can be used each time a new list is created.

Site Script

A site script is a collection of actions that SharePoint runs when creating a new site or list. Actions describe changes to apply to the new list, such as creating new columns, adding views, or content types. The actions are specified in a JSON script, which is a list of all actions to apply. When a script runs, SharePoint completes each action in the order listed.

Site Template (previously known as Site Design)

Site templates can be used each time a new site is created to apply a consistent set of actions. Site templates created using custom site scripts will display in the From your organization tab.

A site script is a JSON string that contains the actions to be taken on a site. A site template, on the other hand, is like a container for the site script. You can attach one or more site scripts to a site template, and when you apply the site template, you execute the actions defined in all of the site scripts. It's like the site template is the visible surface part that can group several site scripts together, and the site scripts are all the action underneath.

Currently, no list template is available From your organization tab.


  • A site template can run multiple scripts. The script IDs are passed in an array, and they run in the order listed.
  • The former term for site templates may still appear in certain cmdlets and script labels as "site design".
  • The schema is case-sensitive.

Create a Site script in JSON

Create the script in JSON that describes the action to be executed on the list. You can view and reference the latest JSON schema file here: https://developer.microsoft.com/json-schemas/sp/site-design-script-actions.schema.json

In addition to constructing the JSON by hand, you can also use third-party tools with graphical user interfaces that generate the site scripts for you, such as sitedesigner.io by Mikko PunamΓ€ki or Site Template Studio by Yannick Plenevaux.

Exporting an existing list as a site script

In our scenario, we will be exporting an existing list configuration as a site script.
First, connect to the SPO admin site using the Connect-SPOService cmdlet. It can be achieved with the following script. The Get-SPOSiteScriptFromList cmdlet prints out the site script to the console. It can be saved into a variable, or you can copy and save it in a JSON file.


Deploy Site Script and Site Template

To use our site script, we need to deploy it to our tenant. We also need to create a site template where we can attach the deployed site script.

1) Add the site script

Each site script must be registered in SharePoint so that it is available to use. Add a new site script by using the Add-SPOSiteScript cmdlet.


After running the cmdlet, you get a result that lists the site script ID of the added script. Keep track of this ID, as it will be needed later when you create the site template.

2) Create the site template

Next, we will create the site template. Run the Add-SPOListDesign cmdlet to add a new site template. Use the script ID saved above when you added the site script. It can run one or more scripts that have already been added.


The JSON response displays the ID of the new site template. It can be used later on to update or modify the site template.

Get the existing Site Script and Site Template

After we have deployed our site script and site template to our tenant, we can see their properties and information about all other deployed site scripts and templates using the Get-SPOSiteScript and Get-SPOListDesign cmdlet.



Use the new site template

Now that we've added a site script and site template, we can use them to create a new list.



I hope this will help all of you! 🧲
Feel free to provide feedback.


πŸš€ "Happy Coding" πŸš€

Saturday 24 July 2021

SharePoint Home site.

 In this blog, we will be discussing the SharePoint Home site.


What is SharePoint Home site?

SharePoint Home site is a Communication site. It is the main landing/home site for your modern SharePoint intranet portal. It brings together news, documents, events, content, conversations, feeds, videos, and other resources.


How to set the site as Home site?

1. Create a new site or use an existing Communication site.

2. Open SharePoint Online Management Shell in administrative mode and connect to SharePoint as a global admin or SharePoint admin.

Here I have installed Microsoft.Online.SharePoint.PowerShell modules.

SharePoint Online Management Shell: Getting Started

3. Run the below command:

Set-SPOHomeSite -HomeSiteUrl https://developer5.sharepoint.com/sites/TheLanding

It will take some time to reflect on the change. In my case, it took 20 minutes. Run the below command to check which site is currently set as the Home site.

Get-SPOHomeSite

Home site can also be set easily through the SharePoint Online admin center.


Go to SharePoint Online admin center at https://YourDomain-admin.sharepoint.com

1. Click on the Settings option.

2. Click on the "Home site" link.

3. Enter the URL of the SharePoint Online communication site that you would like to set as a home site.

4. Press the Save button.


~~~ Things to know ~~~

1. Only PowerShell is available to set a site as the Home site. Currently, it cannot be done through UI as of now.

Update: Home site can be set easily through the SharePoint Online admin center.

2. Only one site can be set as the Home site for a Tenant.

Update: In the latest release, users will be able to set up multiple home sites by using multiple Viva Connections experiences. The feature is currently in private preview and is expected to start rolling out broadly by the end of July 2023.

3. Home site (Communication site) search scope will now be tenant-wide. The default search scope is at the site level only.



4. Home site can be a Hub site also.

5. News coming from the Home site will have a distinguishing highlighted Home site name banner.



The same is available in the SharePoint mobile app.

6. Enables quick access (Home icon) to the Home site from the SharePoint mobile app.


7. The Global Navigation option will be enabled for the Home site now.


Remove site as Home site

Run the below command to remove the site as your Home site.

Remove-SPOHomeSite
Update: Home site can be removed easily through the SharePoint admin center.

πŸš€ "Happy Coding" πŸš€

Sunday 4 July 2021

SharePoint Online Management Shell: Getting Started

In this blog, we will be discussing SharePoint Online Management Shell. The introduction, installation, and some example commands.


Introduction

SharePoint Online Management Shell is a tool that contains a Windows PowerShell module that allows administrators to manage their SharePoint Online subscription in Office 365 using PowerShell.

SharePoint administrators can manage Sites, Users, Tenants and etc. Some of the tasks can be performed in the Microsoft 365 admin center, but not all operations are possible. Command-line operations in Windows PowerShell are composed of a series of commands. We can perform read, write, and execute command-line operations, and they are easier in PowerShell.


Installation

SharePoint Online Management Shell is not present out-of-the-box on the Windows operating system. You need to install the SharePoint Online Management Shell and connect to SharePoint Online.

There are two options:

1. Download and install the SharePoint Online Management Shell .msi package.


2. Install the module from the PowerShell Gallery


Open Windows PowerShell (or CMD) in administrative mode and install the SharePoint Online Management Shell by running the below command:

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

Once the module is installed, execute the below command in administrative mode to check its details:
Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version

To update the SharePoint Online Management Shell, run the below command in administrative mode:
Update-Module -Name Microsoft.Online.SharePoint.PowerShell

To uninstall the SharePoint Online Management Shell, run the below command in administrative mode:
Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell


Run the below command to connect with the SharePoint Online admin center. Enter the SharePoint admin account credentials in the request dialogue box.

Connect-SPOService -Url https://developer5-admin.sharepoint.com




To disconnect and close the connection, run the below command:

Disconnect-SPOService -Url https://developer5-admin.sharepoint.com


πŸš€ "Happy Coding" πŸš€

Tuesday 20 March 2018

Enable Anonymous access to search results.

I am working on one task to display list items using a display template to anonymous users. I have also made the managed search property safe for the anonymous user, but it is still not working for the anonymous user.

Out-of-the-box, the search results webpart (via display template) will try to display data to users (anonymous and authenticated users); authenticated users will see results, while anonymous users will see no results.

Here I will use the PowerShell script to allow list-level anonymous access.



The commented AnonymousPermMask property, according to MSDN, is deprecated and you need to use AnonymousPermMask64.



Instead of ViewFormPages, we need to use AnonymousSearchAccessList, which is described as "Make content of a list or document library retrieveable for anonymous users through SharePoint search. The list permissions in the site do not change".

Then run a full search crawl.


πŸš€ "Happy Coding" πŸš€

Sunday 7 May 2017

SharePoint search query length error.

SharePoint 2013 search results query works properly if select, filter, and other options are in the search query text limit. If the search query limit exceeds the search results, it gives an error.

"An administrator configuration transformed your query into an invalid query"


The search length (in KB) is controlled by the property MaxKeywordQueryTextLength of the SharePoint search service application. The default "MaxKeywordQueryTextLength" value is 4096 (4 KB). Use the PowerShell commands given below.




So increasing the MaxKeywordQueryTextLength value from 4 KB to 8 KB helped in fixing the error.

The reference blog: https://blogs.msdn.microsoft.com/sridhara/2014/05/06/sharepoint-2013-searchserviceexception-the-maximum-allowed-value-is-4096/


πŸš€ "Happy Coding" πŸš€

Sunday 20 November 2016

SharePoint 2013 Apps Environment Configuration.

Setting up a SharePoint development environment has always been challenging, and with the new Apps model in SharePoint 2013, there are even more options and requirements.


First, setup and configure DNS on a Windows server. (http://www.tomsitpro.com/articles/configure-dns-windows-server-2012,2-793.html)

The steps to configure the SharePoint 2013 apps environment.

a) Create Apps Forward Lookup Zone

SharePoint 2013 Apps have their own isolated URLs, which are separate from the URLs of the sites where the app is being deployed and where the app is being used. In order to provide isolation, apps should run in their own domain instead of in the same domain name as your farm. Using a different domain name for apps helps prevent cross-site scripting between apps and SharePoint sites.

Microsoft recommends that the new domain name should NOT be a subdomain of the domain that hosts the SharePoint sites.

1. Open DNS Manager and run it as an administrator from the Start screen.

2. In DNS Manager, right-click Forward Lookup Zones, then the New Zone context menu option.



3. Click Next on the New Zone Wizard dialogue box.

4. On the Zone Type step, select the Primary Zone and click the Next button.

5. On the Zone Name step, enter the app domain name (like spappsdeveloper.com), and click the Next button.



6. On the Dynamic Update step, select the type of dynamic updates you want to allow. Here, with the Allow both nonsecure and secure dynamic updates option selected, click the Next button.





b) Link the SharePoint App Domain to the SharePoint Server

Now DNS will forward all the requests from spappsdeveloper.com to the SharePoint server hosting the apps.

1. In DNS Manager, under Forward Lookup Zones, right-click the newly created zone or app domain (spappsdeveloper.com). Click New Alias (CNAME) from the context menu option.

2. On the New Resource Record dialogue, enter * as the Alias name.

3. For a Fully qualified domain name (FQDN) for target host box, select the Browse button.

4. On the Browse dialogue, select server > Forward Lookup Zones > SharePoint sites host domain > select the record that points to the server that hosts the SharePoint site. Ensure Hosts and Aliases (A and CNAME Records) is selected as the Record types, and click the OK button.

5. Click OK to close the dialogue box.


c) Creating the Subscription Settings and App

 Management Service Applications

1. In SharePoint Central Administration, click the Manage service applications option.

2. Click the New button, then the App Management Service menu item.

3. On the New App Management Service Application dialogue, enter “App Management Service” as the Service Application Name. Select the Use existing application pool option, and then select AppManagementService Pool from the drop-down. Ensure the Create App Management Service Application checkbox is checked. Click the OK button.

4. Or you can use the PowerShell command to create an App Management Service Application.

# get the service application pool
$serviceAppPool = Get-SPServiceApplicationPool -Identity "AppManagementService Pool"

# create app management service application and save its response in variable
$appMngmntSvc = New-SPAppManagementServiceApplication -ApplicationPool
$serviceAppPool -Name "App Management Service" -DatabaseName "App Management Service DB"

# create app management service application proxy and mapping it to service application
New-SPAppManagementServiceApplicationProxy -ServiceApplication $appMngmntSvc

5. Once returned to the list of service applications, ensure both App Management Service Applications are started.

6. Open the SharePoint 2013 Management Shell as an administrator and run.

7. Start the SPAdminV4 and SPTimerV4 service applications.

net start SPAdminV4

net start SPTimerV4

8. Set the domain used to host apps to the new zone created above. It can be set by PowerShell as "done" or via central administration. It can also be done later at the Configure App URL step (see below).

# App Domain Name.
Set-SPAppDomain "spappsdeveloper.com"


9. Start the AppManagementServiceInstance and SPSubscriptionSettingsServiceInstance service instances.

# Start the App Management & Subscription SharePoint services.
Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance


10. Ensure the AppManagementServiceInstance and SPSubscriptionSettingsServiceInstance service instances are Online.

# Check the "Online" status of the App Management & Subscription SharePoint services.
Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance" }


11. Create the SharePoint Subscription Service.

# get the service application pool
$account = Get-SPManagedAccount "WIN-EODPTE6TSSE\sppool"
$serviceAppPool = New-SPServiceApplicationPool -Name "SettingsServiceAppPool" -Account $account

$serviceAppPool = Get-SPServiceApplicationPool -Identity "AppManagementService Pool"

# create subscription settings service application and save its response in variable
$appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool
$appPoolSubSvc -Name "SettingsServiceApp" –DatabaseName "SPSubscriptionSettingsServiceDB"

# create subscription settings service application proxy and mapping it to service application
$proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc




d) Configure the App URL

Set the name for the site subscription.

1. Open Central Administration, click Apps, and then click Configure App URLs.

2. In the App Prefix box, type a name to use for the URL prefix for apps.

3. Or it can also be done by PowerShell.

# SharePoint App Subscription name.
Set-SPAppSiteSubscriptionName -Name "apps" -Confirm:$false



Create a new Developer Site site collection for local App deployment.
Now you're ready to deploy your SharePoint apps to your local SharePoint development environment.

I hope this will help; do write your comments and suggestions.


πŸš€ "Happy Coding" πŸš€