Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is it possible to have a PowerShell script that can modify some item's values in a SharePoint 2007 List or SharePoint Document Library on the last day at 2359 Hrs every month? (If it is possible, it would be nice if can list out links on doing it.)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

To run the script at the time interval you specify, you would have to write the script and then use task scheduler on one of your servers to run the script. You might run into security permissions, here is a good thread on doing it.

http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/e298d613-47b8-4492-92d1-0b55cc8497c1

The script to run is fairly simple

# ------ [ Configuration Section ] ----------------------------------------

$url = "http://localhost/sites/Test"
$listname = "NameOfList"
$fieldname = "Title"
#---------------------------------------------------------------------------
Add-PSSnapin microsoft.sharepoint.powershell

#open output file
$filename = (Get-Date).ToString("u").Replace(":","").Replace(" ","").Replace("-","")+ $url.Replace(":","").Replace(".","").Replace("/","") + "thisiswhatscriptdoes.txt"
$outfile = New-Item -type file $filename

#open the web
$gc = Start-SPAssignment
$web = $gc | Get-SPWeb $url

#open the list 
$list = $web.Lists[$listname]

#Get and store list items in a local variable
$items = [Microsoft.SharePoint.SPListItemCollection] $list.GetItems()

for ($i = 0; $i -lt $list.ItemCount; $i++)
{
    #set local item to loops current item
    $item = [Microsoft.SharePoint.SPListItem] $items[$i]  

    #configure your field edit and output line here, maybe make it an if statement if need be
    $item[$fieldname] = "New Title"
    $item.SystemUpdate()
    $outline = $item[$fieldname] + $item.URL
    Add-Content $outfile $outline


}#end of main for loop

Stop-SPAssignment $gc
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.