Skip to content

Instantly share code, notes, and snippets.

View BasantPandey's full-sized avatar
🏠
Working from home

Basant Pandey BasantPandey

🏠
Working from home
View GitHub Profile
@BasantPandey
BasantPandey / Connect.ps1
Created September 23, 2018 18:28
Connect SharePoint Using Username and password
$ProgressPreference = "SilentlyContinue"
$WarningPreference = "SilentlyContinue"
#Import Modudle
Import-Module $PSScriptRoot\SharePointPnPPowerShellOnline\SharePointPnPPowerShellOnline.psd1 -ErrorAction SilentlyContinue
#Uncomment to run the same script to your local
#$env:APPSETTING_PWord="<Passowrd>"
#$env:APPSETTING_User="<userName>"
@BasantPandey
BasantPandey / AppPermissionRequests.xml
Created September 23, 2018 18:23
SharePoint App Permission request file for tenant full control
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/taxonomy " Right="Read" />
</AppPermissionRequests>
@BasantPandey
BasantPandey / ConnectViaApp.ps1
Created September 23, 2018 16:59
Connect via App
function Connect([string]$Url) {
if ($Url -eq $Global:lastContextUrl) {
return
}
if ($appId -ne $null -and $appSecret -ne $null) {
Connect-PnPOnline -Url $Url -AppId $appId -AppSecret $appSecret
}
else {
Connect-PnPOnline -Url $Url
}
@BasantPandey
BasantPandey / Fields.ps1
Created July 30, 2017 10:51
Create Fields with Configuration CSV file https://sharepointfordeveloper.blogspot.com
#Dev Import
$Path = "C:\SharePointPnPPowerShell2013\"
Import-Module '$Path\SharePointPnP.PowerShell.2013.Commands.dll';
#-----Function to create Site Columns----#
function CreateSiteColumns($csvPath, $SiteURL) {
$Cred = $global:GlobalCred
$newUtfFile = "SiteCollectionSiteColumns_utf8.csv";
@BasantPandey
BasantPandey / RemoveContentType.csv
Last active July 23, 2017 10:27
Remove-PnPContentType using CSV
ContentTypeName
MyContentType
MyContentType2
MyContentType3
MyContentType4
MyContentType5
@BasantPandey
BasantPandey / Set-PnPHomePage.ps1
Last active July 18, 2017 17:37
CSV file for Set multiple sites home page in single loop
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
try {
$path = 'C:\Users\basantp\Documents\PNP Blog Section\Code\Branding'
$inputFile = $path + "\SetHomePage.csv"
$MyFile = Import-Csv $inputFile
foreach ($myRow in $MyFile) {
if ($myRow.SiteURL -ne "") {
@BasantPandey
BasantPandey / Add‑PnPJavaScriptBlock.ps1
Last active July 18, 2017 17:10
Add‑PnPJavaScriptBlock, Add‑PnPJavaScriptLink, Get‑PnPJavaScriptLink and Remove‑PnPJavaScriptLink Methods with Example
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
try {
$URL='<Please enter your url>'
Connect-PnPOnline -Url $URL -CurrentCredentials -ErrorAction Stop
Write-host "Site $URL connected"
#Working code
Add-PnPJavaScriptBlock -Name "myAction" -script ' var ABC = alert("This is my Script block");' -Sequence 20000 -Scope Site
@BasantPandey
BasantPandey / BrandingConfig_Add.csv
Last active July 17, 2017 20:36
Branding Add Custom Action CSV file
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 2.
URL,Action,Name,Title,Description,Group,LocationRibbon,Location,ButtonID,Alt,Sequence,Command,LabelText,TemplateAlias,Image32by32,Image16by16,CommandAction,EnabledScript,CAML1,CAML2,CAML3,CAML4,CAML5,CAML6,CAML7,CAML8,CAML9,CAML10,CAML11,CAML12,CAML13,CAML14
http://yahoo.com,Add,GetItemsCount,Invoke GetItemsCount Action,Adds custom action to custom list ribbon,SiteActions,CommandUI.Ribbon,Ribbon.List.Share.Controls._children,Ribbon.List.Share.GetItemsCountButton,Get list items count,11,Invoke_GetItemsCountButtonRequest,Get Items Count,o1,_layouts/15/images/placeholder32x32.png,_layouts/15/images/placeholder16x16.png,javascript: alert('Total items in this list: '+ ctx.TotalListItems);,javascript: function checkEnable() { return (true);} checkEnable();,"<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=""","""><Button Id=""",""" Alt=""",""" Sequence=""",""" Command=""",""" LabelText=""",""" TemplateAlias=""",""" Image32by32=""",""" Image16by16=""",""" /></CommandUIDefinition></CommandUIDef
@BasantPandey
BasantPandey / BaseCmdlets-Part2.ps1
Created July 14, 2017 20:37
The Get-PnPProperty is same as Load method just add the properties to the context
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
try {
Set-PnPTraceLog -On -LogFile 'C:\Users\basantp\Documents\PNP Blog Section\Code\traceoutput.txt' -Level Error -Delimiter ","
$Url1 = "<URL>"
Connect-PnPOnline -Url $Url1 -CurrentCredentials -ErrorAction Stop
Write-host "Site $Url1 connected".
$web =Get-PnPWeb
Get-PnPProperty -ClientObject $web -Property Id
"Only print the ID : $($web.Id)"
@BasantPandey
BasantPandey / BaseCmdlets-Part1.ps1
Created July 14, 2017 19:46
Introduction to PNP Basic Command Part1
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
try {
Set-PnPTraceLog -On -LogFile 'C:\Users\basantp\Documents\PNP Blog Section\Code\traceoutput.txt' -Level Error -Delimiter ","
$Url1 = "<SiteURL>"
$Url2 = "<SiteURL>"
Connect-PnPOnline -Url $Url1 -CurrentCredentials -ErrorAction Stop
Write-host "Site $Url1 connected".
$Context1= Get-PnPContext