Fun with PowerShell

A couple of days ago I was sitting at my desk, minding my own business, when my spider sense went off — alerting me to a SharePoint site calendar entry with the following error:

“Item does not exist. It may have been deleted by another user.”

Ok, ok, it actually popped up while one of our engineers was updating the shared calendar on our local SharePoint site. They tried to remove an entry, but after deleting it, it never completely went away. Any interaction with the entry returned the message above. I’m sure my spider sense would have caught it eventually though…

So after tinkering with the error for a while, I slipped into the nearest phone booth to put on my PowerShell costume…this took a while though…ever tried to actually FIND a phone booth lately? Now I’ve messed with list objects before, but not orphaned/corrupted/nonexistent/zombie/dark side list items. So I figured this one might be kinda fun.

We started by getting the Web, not too hard right?

$w = get-spweb http://www.somefpwebsite/sites/reallycoolsite

Then we jumped in to grab the calendar…

$Cal=$w.lists["SuperHero Calendar"]

So now $Cal.items has all of our list items in it, the trick is finding one. Since we can’t click on the object, the only thing we really have is the Name. I wanted to see how many entries we had with the same name, so I tossed it in the following loop.

foreach ($listitem in $Cal.Items)
if ($listitem.Name.Contains("Chrisisawesome")) {$listitem.Name}

This will just show you each object named “Chrisisawesome”. Since I had multiple items with this in the name (it’s perfectly normal to schedule “awesome” days on the Cal…right?), and because I couldn’t change the name of the zombie item, I went in and renamed all the other ones. Then all I had to do was change up my loop to grab the one I was wanting–and delete it.

foreach ($listitem in $Cal.Items)
if ($listitem.Name.Contains("Chrisisawesome ")) {$Zombie=$listitem}

Yes, Yes, I know I could have deleted it in the loop, but I’m a chicken… I like to make sure I have the right object and then delete it later. However this did fix the issue! PowerShell saves the day again! Now I just need to do something about this spandex PowerShell suit…

2011-06-14T11:37:07+00:00 June 14th, 2011|


  1. Zammit January 9, 2012 at 9:39 am - Reply

    This saved my bacon today. Thank you very much and good work!

  2. kevin dube April 24, 2012 at 8:46 pm - Reply

    any ideas if the powershell delete gives you the same error?

Leave A Comment