Skip to content

Instantly share code, notes, and snippets.

View asadrefai's full-sized avatar

Asad Refai asadrefai

View GitHub Profile
@asadrefai
asadrefai / Add-FieldToList.ps1
Created August 11, 2015 09:25
Add a field to SharePoint custom list using CSOM PowerShell
function Add-FieldToList()
{
param(
[Parameter(Mandatory=$true)][string]$url,
[Parameter(Mandatory=$true)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$true)][string]$listName,
[Parameter(Mandatory=$true)][string]$fieldName,
[Parameter(Mandatory=$true)][string]$fieldXml,
[Parameter(Mandatory=$false)][bool]$isExistingField
)
@asadrefai
asadrefai / CheckPublishingPageExists.ps1
Created August 11, 2015 09:20
Check if SharePoint Publishing Page Exists using CSOM PowerShell
function CheckPageExists()
{
param(
[Parameter(Mandatory=$true)][string]$siteurl,
[Parameter(Mandatory=$false)][System.Net.NetworkCredential]$credentials,
[Parameter(Mandatory=$false)][string]$PageName
)
begin{
try
{
@asadrefai
asadrefai / New-ItemViewInsideFolders.ps1
Last active August 29, 2015 14:27
SharePoint custom list view to show items inside a folder
function Create-ListViewInner()
{
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 / New-FolderView.ps1
Last active August 29, 2015 14:27
SharePoint list view to show only folders and make it a default
function Create-ListViewFolder()
{
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 / CheckSiteExists.ps1
Created August 11, 2015 07:21
Check if SharePoint Site exists using CSOM PowerShell
function CheckSiteExists()
{
param(
[Parameter(Mandatory=$true)][string]$url
)
begin{
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$web = $context.Web
$context.Load($web)
@asadrefai
asadrefai / CreateContentOrganizerRule.ps1
Created July 27, 2015 11:28
Create content organizer rule using csom PowerShell
# replace these details (also consider using Get-Credential to enter password securely as script runs)..
$username = "SomeOne@SharePoint.onmicrosoft.com"
$password = "YourPassword"
$url = "https://YourSite.sharepoint.com"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
# the path here may need to change if you used e.g. C:\Lib..
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"
@asadrefai
asadrefai / CreateContentOrganiserRule.cs
Created July 27, 2015 11:27
Create content organizer rule using CSOM c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace RecordCentreRule
@asadrefai
asadrefai / GetContentOrganizerRule.ps1
Created July 27, 2015 11:26
Get Content Organizer Rule Using CSOM PowerShell
# replace these details (also consider using Get-Credential to enter password securely as script runs)..
$username = "SomeOne@SharePoint.onmicrosoft.com"
$password = "YourPassword"
$url = "https://YourSite.sharepoint.com"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
# the path here may need to change if you used e.g. C:\Lib..
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"
@asadrefai
asadrefai / GetContentOrganizerRuleAsAnItem.cs
Created July 27, 2015 11:25
Get Content Organizer Rule using CSOM c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace RecordCentreRule
@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{