Wednesday, January 24, 2018

Comparison of Unique Permissions

Hi,

Generally post migration it is really tough to compare unique permissions of each list and library under each subsite.

Recently we have notified the team through calculation metrics through power pivot using excel.

First we have exported permissions of source and target using Permissions Matrix in the Share gate.

After that opened Exported source excel, removed if there are any empty columns.

Selected all the cells, clicked Pivot Table under Insert Tab



















Click Ok on the Create Pivot Table pop up




















Now select URL, Inheritance, Principal Type which comes under Rows section as below

Drag the selected field Principal Type under Values section as below





















Repeat the same for the exported permissions matrix of the target site.
Now open both the files, minimize and compare source and target.

Through this, shall be able to figure in which site the unique permissions are missing in bulk

Saturday, January 20, 2018

Chrono Deployment script

Hi,

Before deployment of Chrono, below is the required configuration in the site

1/ Check if Chrono config list exists, if not, create it with columns ChronoFieldColumnName and ChronoIncrementValue
2/ Check if target list exists, if not, report error and stop execution
3/ Add the chrono field in target list
4/ populate Chrono config list with details from the target list i.e. add Target list GUID under Title Column, text ‘Chrono’ under ChronoFieldColumnName
5/ Update New form if list, edit form if document library
6/ if doc lib, set sets settings to enforce display of edit form after doc creation
if list make the field mandatory
7/ Add the content editor web part to the list->newform.aspx,editform.aspx, document library->editform.aspx
8/Assign  the txt link to the content editor link

// SetChronoField.bat
@ECHO OFF
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\DeploymentScript\SetChronoFieldScript.ps1'"
PAUSE

// SetChronoFieldInputs.xml
<?xml version="1.0" encoding="utf-8"?> 
<Inputs> 
  <ConnectSPConfigOnline SiteURL="siteurl" UserName=”username" Password="password"></ConnectSPConfigOnline> 
  <ConnectSPOnline SiteURL=" siteurl " UserName=" username " Password="password "></ConnectSPOnline>   
  <ConfigList Title="MC2ChronoConfigList" URL="MC2ChronoConfigList" Template="GenericList" ChronoFieldColumnName="ChronoFieldColumnName"/>
<ConfigListFields>
   <ConfigListField Title="ChronoFieldColumnName" InternalName="ChronoFieldColumnName" Group="ListGroup" Type="Text"/>     
   <ConfigListField Title="ChronoIncrementValue" InternalName="ChronoIncrementValue" Group="ListGroup" Type="Number"/>     
</ConfigListFields> 
<Lists>
   <List Title="QoD RC Align Feedback CIO" URL="Lists/QoD%20RC%20Align%20Feedback%20CIO" Template="GenericList" ContentType="Item" ListFieldTitle="Chrono" ListFieldInternalName="Chrono" ListFieldGroup="ListGroup" ListFieldType="Number"/>    
<List Title="QoD RC Align Feedback CIO" URL="Lists/QoD%20RC%20Align%20Feedback%20CIO" Template="DocumentLibrary" ContentType="Item" ListFieldTitle="Chrono" ListFieldInternalName="Chrono" ListFieldGroup="ListGroup" ListFieldType="Number"/>    
</Lists>   
<AddWebParts>
 <AddWebPart Title="ChronoFieldWebPart" RelativePageUrl="/sites/programmequalitedelivery/client/Lists/QoD%20RC%20Align%20Feedback%20CIO/NewForm.aspx" WebPartPath="C:\JB\DeploymentScript\ChronoDeploymentScript\ChronoFieldWebPart.webpart" ContentLink="/sites/programmequalitedelivery/Style%20Library/js/PreSaveAction.txt"/>
 <AddWebPart Title="ChronoFieldWebPart" RelativePageUrl="/sites/programmequalitedelivery/client/Lists/QoD%20RC%20Align%20Feedback%20CIO/EditForm.aspx" WebPartPath="C:\JB\DeploymentScript\ChronoDeploymentScript\ChronoFieldWebPart.webpart" ContentLink="/sites/programmequalitedelivery/Style%20Library/js/PreSaveAction.txt"/> 
 </AddWebParts>
</Inputs>

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

################################################### Get input parameters from XML ###############################  



$outItems = New-Object System.Collections.Generic.List[System.Object]
# Get content from XML file 
[xml]$xmlData=Get-Content ".\SetChronoFieldInputs.xml" 

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

# ConnectSPConfigOnline node 
[System.Xml.XmlElement]$connectSPConfigOnline = $xmlData.Inputs.ConnectSPConfigOnline 
$siteConfigURL=$connectSPConfigOnline.SiteURL 
$userNameConfig=$connectSPConfigOnline.UserName 
$passwordConfig=$connectSPConfigOnline.Password 


#Get Config list details
[System.Xml.XmlElement]$configList = $xmlData.Inputs.ConfigList 
$configListTitle=$ConfigList.Title
$configListUrl=$ConfigList.URL
$configListTemplate=$ConfigList.Template
$configListChronoFieldColumnName=$ConfigList.ChronoFieldColumnName
# Target Lists node 
[System.Xml.XmlElement]$lists = $xmlData.Inputs.Lists

# Target List Fields node 
[System.Xml.XmlElement]$listfields = $xmlData.Inputs.ListFields

# Target Config List Fields node 
[System.Xml.XmlElement]$Configlistfields = $xmlData.Inputs.ConfigListFields

# Web Parts node 
[System.Xml.XmlElement]$webparts = $xmlData.Inputs.AddWebParts

########################################################## Get Credentials ######################################

function GetCredentials() 
{  
    try
                {
                write-host -ForegroundColor Green "Get Credentials and connect to SP Online site: " $siteURL 
    # Convert password to secure string   
    $secureStringPwd = ConvertTo-SecureString -AsPlainText $Password -Force 

    # Get the credentials 
    $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName,$secureStringPwd  

    # Connect to SP online site 
    Connect-PnPOnline –Url $siteURL –Credentials $credentials                   
                }
                catch{
                write-host $_.Exception.Message;
                 }
               
}
function GetConfigCredentials()
{
    try
                {
   write-host -ForegroundColor Green "Get Credentials and connect to SP Online site for COnfig: " $siteConfigURL 
    # Convert password to secure string   
    $secureConfigStringPwd = ConvertTo-SecureString -AsPlainText $passwordConfig -Force 

    # Get the credentials 
    $credentialsConfig = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userNameConfig,$secureConfigStringPwd  

    # Connect to SP online site 
    Connect-PnPOnline –Url $siteConfigURL –Credentials $credentialsConfig 
   }
                catch{
                write-host $_.Exception.Message;
                 }  
}
#######################################################  Create Configuration List#############################

function CreateConfigList() 
                try
                {
                                write-host -ForegroundColor Green "Creating Config List"   

                                $getConfigList=Get-PnPList -Identity $configListUrl

        # Check if list exists 
        if($getConfigList) 
        { 
           write-host -ForegroundColor Magenta $listURL " - Config List already exists"                                                                                                                                   
                                }
        else 
        { 
           # Create new list           
                                   write-host -ForegroundColor Magenta "Creating Config list: " $configListUrl          
                                   New-PnPList -Title $configListTitle -Url $configListUrl -Template $configListTemplate       
                                   
        } 
                }  
                catch
                {
                write-host $_.Exception.Message;
                }
     
}
#################################################################Create Configuration List Fields#####################################
function CreateConfigListFields() 
    try
                {
                                write-host -ForegroundColor Green "Creating Config List Fields" 

                                # Loop through List Fields XML node 
                                foreach($Configlistfield in $Configlistfields.ConfigListField)
                                {
                   
                                                # Get List Field node parameters                                              
                                                $ConfiglistfieldTitle=$Configlistfield.Title
                                                $Configlistfieldinternalname=$Configlistfield.InternalName
                                                $Configlistfieldgroup=$Configlistfield.Group      
                                                $Configlistfieldtype=$Configlistfield.Type
                                               
                                                $getConfigListFields=Get-PnPField -List $configListUrl
                                                foreach($field in $getConfigListFields)
                                                {
                                                if($field.InternalName -eq $Configlistfieldinternalname)
                                                {
                                                                $tag=$tag+1;
                                                }
                                                }
                                                if($tag)
                                                {
                                                                write-host -ForegroundColor Magenta $ConfiglistfieldTitle "-List Field Already exists"
                                                }
                                                else
                                                {
                                                               
                                                                Add-PnPField -List $configListTitle -DisplayName $ConfiglistfieldTitle -InternalName $Configlistfieldinternalname -Type $Configlistfieldtype -Group $Configlistfieldgroup -AddToDefaultView
                                                }                             
                               
                               
                                }
                }
                catch
                {
                write-host $_.Exception.Message;
                }
   
}
function HideConfiglist()
{
                try
                {
                                [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
                                [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

                                write-host -ForegroundColor Green "Get Credentials and connect to SP Online Root site: " $siteConfigURL 
                                # Convert password to secure string   
                                $secureStringConfigPwd = ConvertTo-SecureString -AsPlainText $passwordConfig -Force

                                #Setup Credentials to connect
                                $credentialsConfig = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userNameConfig,$secureStringConfigPwd)

                                #Set up the context
                                $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteConfigURL)
                                $context.Credentials = $credentialsConfig

                                #Get the List
                                $list = $context.Web.Lists.GetByTitle($configListTitle)
                                $list.Hidden = $true
                                $list.Update()
                                $context.ExecuteQuery()
                                Write-Host "List Hidden Successfully!"
                }
                catch
                {
                write-host $_.Exception.Message;
                }

}
#################################################################################################################

#################################################################Create Target List#####################################  
function CreateTargetLists() 
{
                try
                { 
                                write-host -ForegroundColor Green "Creating Target Lists"  
                 
                                # Loop through List XML node 
                                foreach($list in $lists.List) 
                                { 
                                                # Get List node parameters 
                                                $listTitle=$list.Title 
                                                $listURL=$list.URL 
                                                $listTemplate=$list.Template 
                                                $listItemTemplate=$list.ContentType
                                                $listFieldTitle=$list.ListFieldTitle
                                                $listFieldInternalName=$list.ListFieldInternalName
                                                $listFieldGroup=$list.ListFieldGroup
                                               
                                                # Get the list object 
                                                $getList=Get-PnPList -Identity $listURL
                                                $getListFields=Get-PnPField -List $listTitle                                            
                                               
                                                # Check if list exists 
                                                if($getList) 
                                                { 
                                                   write-host -ForegroundColor Magenta $listURL " - List already exists"                                                                                      
                                                   $listGUID=Get-PnPList -Identity $listURL                                               
                                                   
                                                   $outItems.Add($listGUID.Id.ToString()+";"+$listFieldTitle)                                                            
                                                   $outItems.ToArray()                                     

                                                   if($listTemplate -eq "DocumentLibrary")
                                                   {
                                                                                write-host $listTitle "is a document library"                                                         
                                                                                $doclb=Set-PnPList -Identity $listURL -EnableContentTypes $true
                                                   }
                                                } 
                                                else 
                                                { 
                                                   # Create new list 
                                                   write-host -ForegroundColor Magenta "Target list is not available: " $listURL
                                                   exit                       
                                                }
                                                foreach($field in $getListFields)
                                                {                                             
                                                if($field.InternalName -eq $listFieldInternalName)
                                                {
                                                                $tag=$tag+1;
                                                }                                             
                                                }
                                                if($tag)
                                                {
                                                                write-host -ForegroundColor Magenta $listFieldTitle "-List Field Already exists"
                                                }
                                                else
                                                {
                                                                $fielditem=Add-PnPField -List $listTitle -DisplayName $listFieldTitle -InternalName $listFieldInternalName -Type Number -Group $listfieldgroup -AddToDefaultView -Required                                         
                                                }
                                               
                                }
                }             
                catch
                {
                write-host $_.Exception.Message;
                }
}
function AddListGUIDsToConfigLIst() 
{
                try
                {
                                $listItems = Get-PnPListItem -List $configListUrl -Fields "Title"
                                $listItemsCount=$listItems.Count                           
                                if($listItemsCount -eq 0)
                                {                             
                                foreach($outItem in $outItems)
                                {
                                $semicolonpos=$outItem.IndexOf(";")  
                                $listGUIDvalue=$outItem.Substring(0, $semicolonpos)
                                $chronoFieldValue=$outItem.Substring($semicolonpos+1)                          
                                $newItem = Add-PnPListItem -List $configListTitle                            
                                $itmfield=Set-PnPListItem -List $configListTitle -Identity $newItem -Values @{"Title" = "{"+$listGUIDvalue+"}"; $configListChronoFieldColumnName = $chronoFieldValue}                                          
                                }
                                }
                                else
                                {                             
                                foreach($listItem in $listItems)
                                {
                                                               
                                                                Write-Host "------------------------------------" 
                                                                foreach($outItem in $outItems)
                                                                {
                                                                                $semicolonpos=$outItem.IndexOf(";")  
                                                                                $listGUIDvalue=$outItem.Substring(0, $semicolonpos)
                                                                                $chronoFieldValue=$outItem.Substring($semicolonpos+1)
                                                                               
                                                                                if($listItemTitle="{"+$listGUIDvalue+"}")
                                                                                {
                                                                                                write-host -ForegroundColor Magenta $listItemTitle "Already Exists"
                                                                                }
                                                                                else
                                                                                {
                                                                                                $newItem = Add-PnPListItem -List $configListTitle                                                                                            
                                                                                                $itmfield=Set-PnPListItem -List $configListTitle -Identity $newItem -Values @{"Title" = "{"+$listGUIDvalue+"}"; $configListChronoFieldColumnName = $chronoFieldValue}                                    
                                                                                }
                                                                }
                                }

                                }
                }
                catch
                {
                write-host $_.Exception.Message;
                }

}
#################################################################################################################

#################################################################Add the Web Parts #####################################
function AddWebPart()
{
                try
                {
                                write-host -ForegroundColor Green "Adding Web Parts"                 
                               
                                # Loop through Web Parts XML node 
                                foreach($webpart in $webparts.AddWebPart) 
                                {
                                                $webPartRelativePageUrl=$webpart.RelativePageUrl
                                                $webPartPath=$webpart.WebPartPath
                                                $webPartTitle=$webpart.Title
                                                $webPartContentLink=$webpart.ContentLink
                                                $getwebpart=Get-PnPWebPart -ServerRelativePageUrl $webPartRelativePageUrl -Identity $webPartTitle                                                   
                                                if($getwebpart)
                                                {
                                                write-host -ForegroundColor Magenta $webPartTitle "-Web Part Already exists"
                                                $webpart = Get-PnPWebPart -ServerRelativePageUrl $webPartRelativePageUrl -Identity $webPartTitle                   
                                                $webpartId=$webpart.Id                            
                                                Set-PnPWebPartProperty -ServerRelativePageUrl $webPartRelativePageUrl -Identity $webpartId -Key ContentLink -Value $webPartContentLink                          
                                                write-host -ForegroundColor Magenta $webPartTitle "-Web Part ContentLink has been updated"
                                                }
                                                else
                                                {
                                                Add-PnPWebPartToWebPartPage -ServerRelativePageUrl $webPartRelativePageUrl -Path $webPartPath -ZoneId "Header" -ZoneIndex 1