Posts

Showing posts with the label SharePoint 2016

Powershell Scripts 2

Image
Lets see continuation of my previous PowerShell series. This time will start from the basic commands. Load Assembly references in PowerShell Declare Global Variables in PowerShell Pass/Read Command Line arguments Convert DateTime based on regional settings in PowerShell Read RESX value in PowerShell Perform CAML Query in PowerShell Add SharePoint Snapin if (( Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue } Load default/custom Assembly references [void][System.Reflection.Assembly] :: LoadWithPartialName( "System.Net" ) [void][System.Reflection.Assembly] :: LoadWithPartialName( "System.IO" ) [void][System.Reflection.Assembly] :: LoadWithPartialName( "System.Xml" ) [void][System.Reflection.Assembly] :: LoadWithPartialName( "System.Collections.Generic" ) [void][System.Reflection.Assem...

List All Servers in SharePoint Farm - C#

Image
Some times we need to login to all the servers in SharePoint farm just to restart selected Application or Site Pool. Let's see a C# code how to retrieve and recycle selected pools from all the servers in our SharePoint farm. In this series will see How to retrieve all servers in SharePoint farm using C# PS: Please check the NOTE at the very end on this post. First things first import dll's using System ; using Microsoft.SharePoint ; using Microsoft.SharePoint.Administration ; using Microsoft.Web.Administration ; Declare global variables // Global enum Variables public enum Action { Start, Stop, Invalid } ; public enum PoolType { AppPool, SitePool } ; // Global Server variable public List<string> servers = null ; // Global Pool ' s collection variables public List<ApplicationPool> appPoolCollection = null ; public List<Site> siteCollection = null ; Get All SharePoint Farm server names public...

PowerShell Scripts

Image
Let see some of the most useful PowerShell commands in SharePoint to perform below activities. Read SMTP Outgoing Mail Address from Central Administration Get/Set Primary and Secondary Site Administrator Remove user from Site Collection Admin Remove user from Site Groups Set user from direct web Roles Permissions Read SMTP Outgoing Mail Address from CA function LoadEmailConfig() { try { $caWebApp = ( Get-SPWebApplication -IncludeCentralAdministration) | ? { $_ .IsAdministrationWebApplication -eq $true } Write-Host ( "SmtpServer: " + $caWebApp .OutboundMailServiceInstance.Server.Address) Write-Host ( "FromAdress: " + $caWebApp .OutboundMailSenderAddress) } catch { WriteToLog ( "Trying to get eMail Configuration from Central Admin. Exception:- " + $_ .exception.message) } Get/Set Primary/Secondary Site Administrator function GetAdmins() { $site = ...

HTML field & Date Time formatting in powerapps

Image
Hi All, When i dig around powerapps found an interesting control called HTML field. the potential of this control is enormous based on the scenario lets see couple of examples. 1. Formatting Datetime Go to insert -> Text=>HTML Text Insert the control in the list view Add the below in the formula box Concatenate(" < div style = 'height:100%;width:100%;padding:1px;background-color: #418bca;border-right: 1px solid #fff;float:left;' > < div style = 'position: relative;text-align: center;color: #fff;font-size:20px;padding:0px 3px;' > ",Text(DateTimeValue(Text(Modified)),"dd")," < h4 style = 'margin: 5px 0 0 0;color: #fff;text-align: center;' > ",Upper(Text(DateTimeValue(Text(Modified)),"mmm-yy"))," </ h4 > </ div > ") i.e. Concatenate(" < html > ",Text(DateTimeValue(Text(Modified)),"dd")," < html > ")  Output Note :...

Check current login user permission using JSOM in SharePoint 2013/2016

Hi All, One of the easiest way to check the current logged in user privilege in JSOM if (SP.PageContextInfo.get_webPermMasks().has([26])) {        //your code goes here...   } Below are the list of permission types and it's index.   Permission Type Index emptyMask 0 viewListItems 1 addListItems 2 editListItems 3 deleteListItems 4 approveItems 5 openItems 6 viewVersions 7 deleteVersions 8 cancelCheckout 9 managePersonalViews 10 manageLists 12 viewFormPages 13 anonymousSearchAccessList 14 open 17 viewPages 18 ...