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
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 'http://portal.contoso.com'
$list = $web.lists["The List"]
$item = $list.items
$item | get-member
If that doesn't crack the case for you, let us know.
You must be logged in to reply to this topic.