Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 8, 2013 11:27 AM
Hi all,
I want to update a column in a document library which is of "date" type, how can i do this using powershell, can any one provide a script.
Eg : i have a date field with the value "1/16/2013", i want to change this to "2/25/2013"
Best Regards
Anil
All replies (7)
Wednesday, January 9, 2013 6:37 AM âś…Answered
Hi,
the add hh:mm:ss in your date string like:
$item["Date"] = "25/2/2013 00:00:00"
$item.Update()
}
This should work and let us know your result
Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "
Mark As Answer
Tuesday, January 8, 2013 12:02 PM
Hi,
Try this:
Start-SPAssignment -Global
$SPWeb = Get-SPWeb http://site
$List = $SPWeb.Lists["My Form Lib"]
$Items = $List.Items
foreach ($item in $items)
{
$item["Date"] = "2/25/2013"
$item.Update()
}
$SPWeb.Dispose()
Stop-SPAssignment -Global
See this blog for you ref:
Let us know in case any issue
Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "
Mark As Answer
Tuesday, January 8, 2013 12:06 PM
Hi Anil,
This can be done using the following syntax. The bold parts should be changed to fit your environment:
#Add SnapinAdd-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue#Grab the list items$list = (Get-SPWeb http://portal.contoso.com).Lists["List Name"]$items = $list.Items#show the item count for the libraryWrite-Host "$($items.count)"#Enter the Internal name for the column$fieldname = "Datevaluefield"foreach($item in $items){$datefield = $item[$fieldname]if($datefield -eq "1/16/2013"){$item[$fieldname] = "2/25/2013"$item.Update()}}
Please note that I have not tested this particular script, but I have created similar script using the same syntax.
If you have any troubles using it, please let us know.
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Wednesday, January 9, 2013 5:21 AM
Hi Nico,
Thanks for your quick response. I did the same thing as your script, but it is not updating the column value.
I think in the database the "date" value is not storing as it appears in the document library.
I came to know this by displaying the value of this date field.
Eg: The actual value of the date field is "1/16/2013", but when i displayed this value using the below command
write-host ( $item[$fieldname] )
and it is giving the output like below
16-1-2013 00:00:00
That's why I think the condition in the "if" loop is not satisfying. But I also used the "if" statement as below**
**
if($datefield -eq "16-1-2013 00:00:00")
but it is also not working.
Best Regards
Anil
**
**
Wednesday, January 9, 2013 5:24 AM
Hi Hemendra,
Thanks for ur quick response, i did the same thing before posting the actual question, but it is not working, it is not updating the date field.
Best Regards
Anil
Wednesday, January 9, 2013 8:16 AM
Hi Anil,
I have tested and changed my script a little:
#Add Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
#Grab the list items
$list = (Get-SPWeb http://portal.sharepointrelated.com).Lists["Documents"]
$oldDate = Get-Date "16-1-2013"
$newDate = Get-Date "25-2-2013"
$fieldname = "DateField"
$items = $list.Items
#show the item count for the library
Write-Host "$($items.count)"
#Enter the Internal name for the column
foreach($item in $items)
{
$datefield = $item[$fieldname]
if($datefield -eq $oldDate)
{
$item[$fieldname] = $newDate
$item.Update()
}
}
Please only change the bold parts. The rest should be fine. As you are accessing the list through PowerShell, the dates are showed depending on your server regional settings.
Please let us know if it worked.
Nico Martens - MCTS, MCITP
SharePoint 2010 Infrastructure Consultant / Trainer
Monday, January 23, 2017 2:51 PM
in Sharepoint online
I need to fix an entire lists each list has more than 100 items.
I need to update 3 different dates items. startDate, endDate, expirationDate
I need to add 1 full day to each of those.
How can I accomplish this?
i.e. startDate is 01/17/2016 and I need to update it to 01/18/2016
and so on.
Thanks in advance