Compare/Update items in a Document Library

by jf781 at 2012-10-04 19:45:26

Hello – First off I’m just learning PowerShell so be gentle. I am trying to create a script that would run twice daily that would look at all of the items in a document library (under 300 items) accomplish two tasks.

- If there is another item in the list that has the same name as it, it would delete the older of the two items.
- Check each item’s “Created” date, if it is greater than 14 days it would change a field from “Yes” to “No”

I have been able to access the library and get a list of the current items but am not sure what my next step would be. I also know this is a kind of an odd request but I’m not looking for someone to do the work for me – More of pointing the flashlight in the right direction type of thing. Don’t learn much when you copy and paste.

Any questions to help clarify please let me know

by ToddKlindt at 2012-10-05 12:34:54
Hi Joe,
If you’re just looking for guidance, I have two words for you (okay, one hyphenated word); get-member.

Once you have a variable for a list item, run it through get-member. That’ll give you all the fields that are available to you. Hopefully from there you can figure out how to see an item’s name, how to delete an item, and how to find the last modified date of an item.

The psuedo code would look something like this:
$web = get-spweb ''
$list = $web.lists["The List"]
$item = $list.items[0]
$item | get-member

If that doesn’t crack the case for you, let us know.