How to Set Environmental Variables in Windows Server 2012 R2

Sathish Nadarajan
 
Solution Architect
August 6, 2018
 
Rate this article
 
Views
38470

 

Today I was installing Python on the Windows Server 2012 R2 VM. Once installing the Python, we need to add the Installation path of the Python to environmental variable PATH.

In the earlier versions of windows, we will see the environmental variables in the computer properties. But in Win Server 2012, it is moved to the Control panel.

1. Go to Control Panel.

clip_image002

2. Click on “System and Security”

clip_image004

3. Click on “System”

4. Click on “Advanced System Settings” on the left pane.

clip_image006

5. System Properties will be opened as below.

clip_image008

Click the Environment Variables and add your PATH. It works the same way as that of the earlier versions. But only the location is changed.

Happy Coding,

Sathish Nadarajan.

Category : Windows

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

How to Set a Property Bag Key as an Indexed (Queriable via Search) Programmatically using C# Client Side Object Model (CSOM)

Sathish Nadarajan
 
Solution Architect
March 30, 2017
 
Rate this article
 
Views
2976

Recently in our projects, we are using a lot of Property Bag Values. But in some specific requirement, we were trying to Search the Property Bag from the SharePoint Keyword Query. To do that, we want the Property Bag Key to be Indexed as Queryable. That, we need to do programmatically as part of our Provisioning. Let us see, how to do that. The code is very straight forward.

Basically, we are updating a Property Bag called vti_indexedpropertykeys with the values Encoded.

 namespace Console.Office365
 {
     using Microsoft.SharePoint.Client;
     using OfficeDevPnP.Core;
     using System;
     using System.Linq;
     class Program
     {
         static void Main(string[] args)
         {
             AuthenticationManager authManager = new AuthenticationManager();
             var clientContext = authManager.GetSharePointOnlineAuthenticatedContextTenant("https://***.sharepoint.com/sites/CommunitySite/", "Sathish@******.com", "**********");
             Web web = clientContext.Web;
             clientContext.Load(clientContext.Web);
 
             clientContext.Load(clientContext.Site);
             clientContext.Load(clientContext.Site.RootWeb);
             PropertyValues properties = clientContext.Web.AllProperties;
             clientContext.Load(properties);
             clientContext.ExecuteQuery();
 
             // Get the Existing Property Bag Values from the Indexxed Property Keys
             var oldPropertyBagValue = clientContext.Web.PropertyBagContainsKey("vti_indexedpropertykeys") ? Convert.ToString(properties["vti_indexedpropertykeys"]) : string.Empty;
 
             string[] O365Properties = new string[] { "PropertyBagKey1", "PropertyBagKey2", "PropertyBagKey3"};
             
 
             string newPropertyBagValue = string.Empty;
 
             // Get the New Property Bag Values.  In our case, it is propertybagkey1, propertybagkey2 etc., 
             foreach (var propertiesString in O365Properties)
             {
                 newPropertyBagValue += Convert.ToBase64String(System.Text.Encoding.Unicode.GetBytes(propertiesString)) + "|";
             }
 
             // Add the new values to the existing ones.
             newPropertyBagValue = oldPropertyBagValue + newPropertyBagValue;
 
             // take the Unique Items.  There could be changes that a key can be repeated.  So always using Distinct.
             var distinctNewPropertyBagValue = newPropertyBagValue.Split('|').Distinct().ToArray();
 
             // Update the Property Bag Key
             properties["vti_indexedpropertykeys"] = string.Join("|", distinctNewPropertyBagValue).Trim();
 
 
             web.Update();
             clientContext.Load(web.AllProperties);
             clientContext.ExecuteQuery();
         }
     }
 }
 

Happy Coding,

Sathish Nadarajan.

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

How to Set the Page Layout in SharePoint 2013 using PowerShell

Sathish Nadarajan
 
Solution Architect
December 5, 2015
 
Rate this article
 
Views
11747

In this article, let us see how to change the PageLayout of a Publishing page using PowerShell in SharePoint 2013. All the PowerShell Scripts will be very much helpful and handy during the time of preparing the deployment package.

The Script is straight forward and does not require any explanation I guess.

 ##================================================================================================
 ## Description	: To do the below two items.
     #1. Update the PageLayouts of the Existing Pages
 ## Author		: Sathish Nadarajan
 ## Date			: 16-Nov-2015
 ##================================================================================================
 
 ##============================================ Setup Input Paths ===========================================================
 
 cls
  
 $Host.UI.RawUI.WindowTitle = "-- Update the Page Layouts of the Existing Pages --"
 
 $StartDate = Get-Date
 Write-Host -ForegroundColor White "------------------------------------"
 Write-Host -ForegroundColor White "| Update the Page Layouts of the Existing Pages |"
 Write-Host -ForegroundColor White "| Started on: $StartDate |"
 Write-Host -ForegroundColor White "------------------------------------"
 
 $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
 $LogFile = ".UpdatePageLayout-$LogTime.rtf"
 
 #start-transcript $logfile
 
 $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
 Set-Location $scriptBase
 
 $ErrorActionPreference = "Stop"
 
 function AddPowerShellSnapin()
 {
     try
     {
         Write-Host "Adding PowerShell Snap-in" -ForegroundColor Green
         # Try to get the PowerShell Snappin.  If not, then adding the PowerShell snappin on the Catch Block
         Get-PSSnapin "Microsoft.SharePoint.PowerShell" 
     }
     catch
     {
         if($Error[0].Exception.Message.Contains("No Windows PowerShell snap-ins matching the pattern 'Microsoft.SharePoint.PowerShell' were found"))
         {
             Add-PSSnapin "Microsoft.SharePoint.PowerShell"
         }
     }
     Write-Host "Finished Adding PowerShell Snap-in" -ForegroundColor Green
 }
 
 
 function UpdatePageLayout([string]$WebURL, [string]$PageLayoutName,[string]$PublishingPageName)
 {
     #Get the web and page
     $Web = Get-SPWeb $WebURL
     
     #Get Publishing Site and Web
     $PublishingSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Web.Site)
     $PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
  
     #Get New Page Layout
     $SitePageLayouts = $PublishingSite.GetPageLayouts($false)
     $NewPageLayout = $SitePageLayouts | ? {$_.Name -eq $PageLayoutName}
 
     #Get Pages Library
     $PublishingPage = $PublishingWeb.GetPublishingPage($WebURL + "Pages/" + $PublishingPageName)  
     $PublishingPage.CheckOut()
     $PublishingPage.Layout = $NewPageLayout
     $PublishingPage.ListItem.Update();
     $PublishingPage.CheckIn("Page layout Updated via PowerShell")
     $PublishingPage.ListItem.File.Publish("Published via PowerShell")
     if ($PublishingPage.ListItem.ParentList.EnableModeration)
     {
         $PublishingPage.ListItem.File.Approve("Publishing Page Layout Updated!");
     }
  
     write-host "Updated Page layout on: "$PublishingPage.url -ForegroundColor Green
 }
  
 
  
 
  
  
  try
 {
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
     [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration")
         
     $ConfigXmlPath = $scriptBase + "ConfigXMLPageLayouts.Config.xml"
     Write-Host "Read the Config Values" -ForegroundColor Green 
     [Xml]$Config = Get-Content $ConfigXmlPath  
     
     AddPowerShellSnapin
     
     foreach($Page in $Config.Configuration.Pages.Page)     
     {
         UpdatePageLayout $Config.Configuration.PublishingSite.URL $Page.LayoutName $Page.Name
     }
 }
 catch
 {
     Write-Host "Custom Exception Happened on Main : " + $Error[0].Exception.Message -ForegroundColor Red  
 }
 

And the Config XML is as follows.

 <Configuration EnvironmentName="Dev">
   <PublishingSite URL="http://MySiteCollectionURL/" />
   <Pages>
 	<Page Name="home.aspx" LayoutName=" Home-Layout.aspx"></Page>
 	<Page Name="books.aspx" LayoutName="Topic-Layout.aspx"></Page>
   </Pages>
 </Configuration> 
 
 

 

 

Happy Coding,

Sathish Nadarajan.

Category : PowerShell, SharePoint

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment