Skip to content

Instantly share code, notes, and snippets.

View asadrefai's full-sized avatar

Asad Refai asadrefai

View GitHub Profile
@asadrefai
asadrefai / AddField-InContentType.ps1
Last active August 29, 2015 14:18
Add a site column into content type SharePoint 2013 using csom PowerShell
Try{
#Loading SharePoint Client side namespaces
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Publishing.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll'
}
catch {
Throw "Unable to load SharePoint Client runtime"
@asadrefai
asadrefai / ReOrderContentTypes.ps1
Last active August 29, 2015 14:19
Reorder content types in SharePoint list csom PowerShell
#Load SharePoint client assemblies
#
Try{
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Publishing.dll'
Add-Type -Path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll'
}
catch {
@asadrefai
asadrefai / Check-ListExists.ps1
Created May 11, 2015 14:52
Check if SharePoint list exists using PowerShell
function Check-ListExists()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName
)
begin{
try
@asadrefai
asadrefai / Set-PermissionOnList.ps1
Created May 11, 2015 14:56
Set permissions on SharePoint list using CSOM PowerShell
function Set-PermissionsOnList()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName,
[Parameter(Mandatory=$true)][string]$GroupName,
[Parameter(Mandatory=$true)][string]$Roletype
)
begin{
@asadrefai
asadrefai / Delete-ListView.ps1
Created May 11, 2015 15:03
Delete a list view of a SharePoint list using CSOM PowerShell
function Delete-ListView()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName,
[Parameter(Mandatory=$true)][string]$viewName
)
begin{
@asadrefai
asadrefai / Remove-ItemContentType.ps1
Created May 11, 2015 15:11
PowerShell to remove item content type from a SharePoint list
function Remove-ItemContentTypeFromAList(){
#delete item content type from list
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$web = Get-SPWeb "http://YourSite.com"
$list = $web.Lists["Your List Name"]
$ctToRemove = $list.ContentTypes["Item"]
if($ctToRemove)
{
Write-Host "Item Content Type Exist ready to delete"
$list.ContentTypes.Delete($ctToRemove.Id)
@asadrefai
asadrefai / Change-DisplayNameOfField.ps1
Created May 11, 2015 15:13
PowerShell to change the display name of a field in a SharePoint List
function Change-DisplayNameOfField()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName,
[Parameter(Mandatory=$true)][string]$fieldName,
[Parameter(Mandatory=$true)][string]$displayName
)
@asadrefai
asadrefai / Check-ColumnExists.ps1
Created June 1, 2015 15:00
Check if field exists in a SharePoint list
function Check-ColumnExists()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName,
[Parameter(Mandatory=$true)][string]$fieldName
)
begin{
try
@asadrefai
asadrefai / Reorder-ContentTypeFields.ps1
Created June 2, 2015 09:56
Reorder fields in a SharePoint content type using csom PowerShell
function Reorder-ContentTypeFields()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$ContentTypeName
)
begin{
try
@asadrefai
asadrefai / AddFieldFromParentContentType.ps1
Last active August 29, 2015 14:22
Add columns into content type from parent content type using csom PowerShell
function AddFieldFromParentContentType()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$ContentTypeName,
[Parameter(Mandatory=$true)][string]$FieldInternalName
)
begin{