1

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.)

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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