Sunday, December 17, 2017

Remove List Column using PnP PowerShell

Hi,

There was a requirement of deleting list column using PnP Powershell

For this, I have written the PnP PowerShell script to take column name from xml and web urls from csv as below.

Please make sure to have all the files are in the same folder

//RemoveListColumnInputs.xml
<Inputs>
<ConnectSPOnline UserName="username" Password="password" RemoveColumnName="Phase"></ConnectSPOnline>
</Inputs>

//RemoveListsColumnInputs.csv
SiteCollectionUrl,WebUrl,ListTitle,ListUrl,ContentTypeName,ContentGroup
sitecollectionurl,weburl,listrelativeurl,contenttypename,contenttypegroup

//RemoveListsColumnScript.ps1
############################################################## Logging #########################################
  
$date= Get-Date -format MMddyyyyHHmmss 
start-transcript -path .\Log_$date.doc  

################################################### Get input parameters from XML ###############################  
# Get content from XML file 
[xml]$xmlData = Get-Content ".\RemoveListColumnInputs.xml" 

# ConnectSPOnline node 
[System.Xml.XmlElement]$connectSPOnline = $xmlData.Inputs.ConnectSPOnline 
$userName=$connectSPOnline.UserName 
$password=$connectSPOnline.Password
$removecolumnname=$connectSPOnline.RemoveColumnName

$weburlinputs= Import-CSV .\RemoveListsColumnInputs.csv

function RemoveListsColumn() 
{  
               
                try
                {
                                $weburlinputs | foreach-object {
                                $WebUrl = $_.WebUrl
                                $ListTitle =$_.ListTitle    
               
                                write-host $WebUrl
                                write-host $ListTitle       
                               
                                #Convert password to secure string        
                                $secureStringPwd = ConvertTo-SecureString $password -AsPlainText -Force         
                               
                                # Get the credentials                                                                                     
                                $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName,$secureStringPwd  
                               
                                write-host -ForegroundColor Green "Connecting to Site Web URL":$webURL
                               
                                Connect-PnPOnline -Url $WebUrl -Credentials $credentials          
                               

                                write-host -ForegroundColor Green $removecolumnname "is being removed from the list":$ListTitle
                               
                                Remove-PnPField -List $ListTitle -Identity $removecolumnname -Force                  
                               
                                write-host -ForegroundColor Green $removecolumnname "has been removed from the list":$ListTitle
                                }
                }
                catch
                {
                write-host $_.Exception.Message;
                }

}
               

#################################################################  Initiate #####################################
function Initiate() 
     write-host -ForegroundColor Green "Initiating the script.................. "  
                 RemoveListsColumn
                Disconnect-PnPOnline 
                 write-host -ForegroundColor Green "Completed!!!!"  
}
#################################################################################################################

Initiate 
Stop-Transcript 
  


Thanks & Regards,

Naga Sudheer M

Saturday, August 19, 2017

Column Auto Increment through SharePoint Designer

Hi,

After adding a new item in the Sharepoint list, value should be incremented under a Sharepoint column ‘ChronoListField’.

This has to be achieved with SharePoint designer workflow.

To achieve this, first we have created a list ‘ChronoIncrement’ and added a column ‘AutoIncrement’ of type number.

Now we have created workflow in the list where column value needs to be incremented with newly added list item.

Through Do Calculation we have done the manipulation as below i.e.

Under Data source, have selected list ‘ChronoIncrement’ and have selected field ‘AutoIncrement’ field to retrieve.

To find the list item, have selected ID field and the Value ‘1’
Incremented the value and have assigned to a variable called ‘incrementedval’
After this have assigned variable ‘incrementedval’ value to SharePoint column ‘ChronoListField’
Then updated the value back to list ‘ChronoIncrement’ under column ‘AutoIncrement’ w.r.t ID value ‘1’

After this, logging the incremental value to the history list
Ended the workflow as below

At last below is the workflow that has been published
End Results
Below are the results that have been achieved