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 / 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 / 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 / RemoveContentType.csv
Last active July 23, 2017 10:27
Remove-PnPContentType using CSV
ContentTypeName
MyContentType
MyContentType2
MyContentType3
MyContentType4
MyContentType5
@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 / 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 / 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 / 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 / BaseCmdlets.ps1
Last active January 25, 2021 09:18
Simple How to use the Get-PnPContext and other commands
#Please make sure you have installed all the powershell package.
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 = "https://sharepoint-xxx.com/xx/xxx"
Connect-PnPOnline -Url $Url1 -CurrentCredentials -ErrorAction Stop
Write-host "Site connected".
$Context= Get-PnPContext # Connect and store the context
$Web = $Context.Site.RootWeb
@BasantPandey
BasantPandey / SharePointSendEmail.js
Last active June 27, 2021 03:22
Send Email using SharePoint Rest API
var Email= function(){
// Email Either email groupname or email address
var from = 'abc.yahoo.com',
to = 'abc.yahoo.com',
cc = 'abc.yahoo.com',
subject='My Email Subject';
this.options = this.options || {};
this.options['fromEmail'] = this.options['fromEmail'] || {};
this.options['toEmail'] = this.options['toEmail'] || {};