Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a timer job that is running some powershell.

The script creates a content database and then attempts to create a site collection. If run from powershell prompt the script works fine. If I comment out the New-SPSite and run within timer job it works fine. The error occurs running New-SPSite within the timer job.

$date = Get-Date  
$dateString = $date.ToString("MMddHHmm")    
$server = "SERVER-NAME"  
$dbname = "prefix" + $dateString  
$webapp = "http://SERVER-NAME:4321/"   
$siteName = "http://SERVER-NAME:4321/sites/" + $dbname  
$quotaTemplateName = "1GB"   
$owner1 =   "DOMAIN\svcUser"  

New-SPContentDatabase -Name $dbname -DatabaseServer $server -WebApplication $webapp | out-null 

New-SPSite -URL $siteName -OwnerAlias $owner1 -SecondaryOwnerAlias $owner2 -ContentDatabase $dbname -Template STS#0 | out-null 

The error I get is ERROR: Failed to OpenThreadToken, LastError=1008

The full log entry is here

03/21/2013 15:14:25.28  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  6tf0    Medium  Entering BeginProcessing Method of New-SPSite.  b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.28  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  6tf0    Medium  Leaving BeginProcessing Method of New-SPSite.   b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.28  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  6tf0    Medium  Entering ProcessRecord Method of New-SPSite.    b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.31  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   Topology    95kp    High    Creating site http://ids-devsvr2:4321/sites/Paul20130321151403  b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.31  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   Topology    f3y4    High    Creating site /sites/Paul20130321151403 in content database Paul20130321151403  b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   General 7fd9    Unexpected  ERROR: Failed to OpenThreadToken, LastError=1008    b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   Topology    95kq    High    Creating top level site at http://ids-devsvr2:4321/sites/Paul20130321151403 b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:25.50  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   General 72jz    Medium  Creating site: URL "/sites/Paul20130321151403"  b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.14  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   General 7fd9    Unexpected  ERROR: Failed to OpenThreadToken, LastError=1008    b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.14  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   General 72k1    High    Cannot create site: "http://ids-devsvr2:4321/sites/Paul20130321151403" for owner "NDE\svcdevdbeng", Error: , 0x2828ae40 b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   General 8kh7    High    Cannot complete this action.  Please try again. b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   Topology    6141    Critical    The site /sites/Paul20130321151403 could not be created.  The following exception occurred: Cannot complete this action.  Please try again..    b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   Monitoring  b4ly    High    Leaving Monitored Scope (Creating Site ). Execution Time=1171.4718  b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  6tf2    High    Cannot complete this action.  Please try again. b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  91ux    High    Error Category: InvalidData    Target Object  Microsoft.SharePoint.PowerShell.SPCmdletNewSite  Details  NULL  RecommendedAction NULL    b658e164-c21c-413f-af6d-c735d373bd15      
03/21/2013 15:14:26.49  OWSTIMER.EXE (0x1F08)   0x1A90  SharePoint Foundation   PowerShell  6tf0    Medium  Leaving ProcessRecord Method of New-SPSite. b658e164-c21c-413f-af6d-c735d373bd15      
share|improve this question
    
Maybe you need to use impersonation with the apppool account? –  Benny Skogberg Nov 13 '13 at 18:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.