Take the 2-minute tour ×

I have a simple list with an event receiver for the following events:

  • ItemAdded
  • ItemUpdating
  • ItemDeleting

I confirmed that the event receiver fires when adding/updating/deleting an item from the SharePoint user interface.

However, it doesn't fire when I create the list item from a PowerShell script. The item is added to the list but the event receiver doesn't fire. Any thoughts on why this is?

Here's the relevant snippet of the PowerShell script:

# read offices from Data-Offices.xml
$officeData = [xml](Get-Content .\data\Data-Offices.xml)

# iterate through items and create them in Office list
foreach ($office in $officeData.offices.office)
    $newItem = $list.items.Add();
    $newItem["Title"] = $office.title;
    Write-Host "Added Office: " $office.title

Wondering if there's a permissions issue here ... Tried running the script as an administrator but that didn't resolve the issue.

Thank you

share|improve this question
What permissions are you running your cmd-let with? Make sure it has the privileges to execute the code in question (eg. full control of web application). Also, I notice sometimes closing the shell and re-open works (not sure about your situation). –  Mary Rivers Nov 9 '11 at 18:45
Figured it out ... The PowerShell script is running in a different context, and it's not able to find a web.config setting that our SharePoint application uses (appSettings for the ConfigStore project). –  George Durzi Nov 9 '11 at 19:55
I have the same problem you desrcibed. How did you solve it ? Thank you –  user7177 Mar 1 '12 at 15:09

1 Answer 1

Precede your code block with something similar to the following to obtain the same context for the event handler to fire -

$fooWebURL = "http://fooWebSite"; 
$fooWeb = Get-SPWeb -Identity $fooWebURL; 
$fooFolder = $fooWeb.GetFolder("Documents"); 
$fooFileCollection = $fooFolder.Files;

then merge & iterate thru files upload..

share|improve this answer

Your Answer


