Showing posts with label Share Point 2013. Show all posts
Showing posts with label Share Point 2013. Show all posts

Wednesday, 2 December 2015

Designer workflow is not sending email to SharePoint group


I created a workflow in SharePoint Designer, which has to send an email when an item is added in a list. It works as expected when the email assign to a user. However, if I give SharePoint group instead of user, it does not send email to the members of the group.

First make sure that the group has at least “read only” access to the entire site.

Go to Site Settings -> People and groups -> Your group settings -> select an option which says that the members in this group are accessible to everyone.



Tuesday, 12 May 2015

PowerShell Script : Change content type for all documents in a library

I had come up this requirement after migration. The old migrated library is populated with thousands of files having the default content type set to ‘Document’. All the documents now need to be assigned a specific content type.
If we have a large library Powershell is the easy way to change the content type. Before you run the script, make sure the new content type is associated with the library.
The script below sets up a function which will look at the document library and modify all files associated with the specified content type to a different one.

'Drop Off Library' is my library name and want to update all files associated with 'Document' content type to 'Techsheet'.

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$webUrl = "http://server:portno/sites/yoursite"
$web = Get-SPWeb $WebUrl
$list = $web.Lists["Drop Off Library" #Library Name
$oldCT = $list.ContentTypes["Document" #Old Content Type Name
$newCT = $list.ContentTypes["Techsheet" #New Content Type Name
$newCTID = $newCT.ID
write-host $newCTID
for($i=0; $i -le $web.Lists.Count; $i++)
    {
    foreach($item in $list.items[$i])
        {
        if ($item.ContentType.Name -eq $oldCT.Name)
            {
                 #Check the check out status of the file
                if ($item.File.CheckOutType -eq "None")
                {
                    #Change the content type association for the item
                    $item.File.CheckOut()
                    write-host "Resetting content type for file" $item.Name "from" $oldCT.Name "to" $newCT.Name
                    $item["ContentTypeId"] = $newCTID
                    $item.Update()
                    $item.File.CheckIn("Content type changed to " + $newCT.Name, 1)
                }
            }
        }
    }
$web.Dispose() 


Thursday, 5 March 2015

Bulk Indexing documents to Multiple Libraries using Powershell

Suppose we have a Document Library with large no. documents and we want to update the metadata which is kept in an excel file from local drive using PowerShell. Like this we have Multiple document Libraries and Metadata templates. Below is the process to iterate through each document library with its excel templates.
Steps

As all of you know there is no direct way to update metadata from Excel. So we have to convert excel to CSV format. And avoid space in column names in the CSV file.
1. Save as excel file to CSV format
2. Create a folder structure in windows drive to store the list templates in CSV format.


3. Create a list in SharePoint to store the folder path for each CSV template corresponding to each Library. Here the List name is 'IndexList'
4. Map the column names such as LibraryName, LibraryUrlName and TemplatePath in the script
5. Map the column names from CSV to the corresponding column names from SharePoint Library in the script.


if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null

{

Add-PSSnapin Microsoft.SharePoint.PowerShell

} 

$url = "http://sitename:portno/"

$OpenWeb = Get-SPWeb $url

$DocumentIndexing = $OpenWeb.Lists["IndexList"]

ForEach($item in $DocumentIndexing.Items)

{

$docLibraryName = $item["LibraryName"]

$docLibraryUrlName = $item["LibraryUrlName"]

$localFolderPath = $item["LinkTitle"]

$docLibrary = $OpenWeb.Lists[$docLibraryName]

Write-Host $localFolderPath

$file = Get-Content "$localFolderPath"

#Open file

function Update-SPList()

{

$data = Import-Csv $localFolderPath

$OpenWeb = Get-SPWeb $url

$folder = $OpenWeb.getfolder($docLibraryUrlName)

Write-Host $folder

foreach($row in $data)

{

#CAML query compares LinkFilename in the Library and Name Column in the CSV

$spQuery = New-Object Microsoft.SharePoint.SPQuery

$camlQuery = '<Where><Eq><FieldRef Name="LinkFilename" /><Value Type="Text">'+ $row.Name +'</Value></Eq></Where>'

$spQuery.Query = $camlQuery

$listItems = $docLibrary.GetItems($spQuery)

foreach($item in $listItems)

{

# List Out all column names from all CSV Templates of without Duplication and pass the value to Library columns.

   Write-Host "Updating" $item["LinkFilename"] "with" $row.Name

   $item["Content Type"] = $row.Document_Category

   $item["DATE_x0028_MM_x002f_YY_x0029_"] = $row.DATE

   $item["Location"] = $row.Location

   $item["Licence_x0020_No"] = $row.Licence_No

   $item["Center"]=$row.Center

   $item["Ticket"]=$row.Ticket_No

   $item["Amount"]=$row.Amount

   $item["Course"]=$row.Course

   $item.Update()

}

#Clear all rows except the CSV column Names

(Get-Content $localFolderPath |  Select -First 1) | Out-File $localFolderPath 

}
}

Update-SPList

if($OpenWeb)

{

$OpenWeb.Dispose()

}

}


Once it is updated the rows will be automatically deleted from the CSV template .

Thursday, 5 February 2015

How to update a SharePoint list column through Powershell

PowerShell Script for updating SharePoint List Column

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
 Add-PSSnapin Microsoft.SharePoint.PowerShell
}
 
#Script settings
 

$web = Get-SPWeb https://sitename:port/

$list = $web.Lists["ListName"]

foreach ($item in $list.Items)
{
$item["Column1"] = "Text";
$item["Column2"] = "Text";
$item.Update();
}

write-host "Success"
 #Dispose web
 
$web.Dispose()

If it is a large List we can update the List column batch wise. Below is the script for updating share point list item batch wise

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)

{
  Add-PSSnapin Microsoft.SharePoint.PowerShell


}
 
#Script settings
 
 

$web = Get-SPWeb https://sitename:port/

$list = $web.Lists["Tasks"]

$spQuery = New-Object Microsoft.SharePoint.SPQuery

$spQuery.ViewAttributes = "Scope='Recursive'";

$spQuery.RowLimit = 100

$caml = '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'

$spQuery.Query = $caml

do

{
$listItems = $list.GetItems($spQuery)

$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

foreach($item in $listItems)

{
$item["Column1"] = "Text";

$item["Column2"] = "Text";
$item.Update();

}

}
while ($spQuery.ListItemCollectionPosition -ne $null)

write-host "Success"
#Dispose web
$web.Dispose()

 

Hope this helps..

Sunday, 1 February 2015

Upload Files to Sharepoint Document Library Using Task Scheduler



Steps to configure Task Scheduler with PowerShell scripts:

1. Create a folder containing the files to upload to SharePoint. In my case it is C:\Documents

2. Create another  folder to keep the Script file (i.e. BulkUpload.ps1). The script for uploading documents to share point library is already mentioned in my previous Blog.


 
3. Open Start -> Task Scheduler, see below Screenshot


     
4. Create a New Task.Following Window will appear, Give a Name to the Task and Select Two options mentioned in Screenshot to run as administrator



5. Click Action Tab -> New. A window will appear to set the actions



Enter powershell.exe as Program\script and the path to power shell script (C:\TaskSchedulerScript\BulkUpload.ps1) as arguments. Click OK
 
 
6. Click on Triggers ->New ->Give scheduler Time to run


7. When you click OK to confirm task creation, you will be prompted to enter the password for the account you selected to run the script.

8. Enter the password and click OK

9. You can see a task is created in the Task Scheduler Library (if not, click refresh in the right-hand panel)