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 written a PowerShell script to mimic Visual Studio's Deploy command. Specifically, I need the lists defined in a Feature to be deleted, the solution updated and the Feature activated with blank list instances. This works if I do it manually, but not if I use the Enable-SPFeature CmdLet or spWeb.Features.Add(Guid) method.

After running Enable-SPFeature, the lists appear to be added to the site, but if I attempt to add an item, I get the error 'List does not exist'.

Here is a dumb-down example of my script. It does not throw any exceptions.

$spWeb.GetList($spUrl + "List1").Delete()

Disable-SPFeature -identity e4792def-2152-4ae8-9028-db4409f5078e -Url $spWeb.Url -Confirm:0

Update-SPSolution -identity d7743a31-4036-4475-a1e6-b9ae4dcb1d56 -Literalpath $wspPath -gacdeployment

Enable-SPFeature -identity e4792def-2152-4ae8-9028-db4409f5078e -Url $spWeb.Url -ea Stop
#$spWeb.Features.Add("e4792def-2152-4ae8-9028-db4409f5078e")

If I comment out the line Enable-SPFeature and instead Active the feature through Manage Site Features, the Lists are added correctly and I don't get the 'List does not exist' error.

[EDIT] I added a wait method similar to what Steve recommended. After inspecting the output from Visual Studio, I refactored my script to perform the SP CmdLets in the same order as VS and wait for the asynchronous commands to complete before executing the next step. I still get the same error.

  1. Reset IIS
  2. Disable Features
  3. Uninstall Solution
  4. Remove Solution
  5. Delete Lists
  6. Add Solution
  7. Install Solution
  8. Enable Features
share|improve this question
1  
Please update your question with the code which is used in the feature. Are you using SPContext? –  Anita Boerboom Sep 17 '11 at 7:49
    
There is far too much code in the feature to paste here. I am not using SPContext. –  user602441 Sep 19 '11 at 19:41
    
Too bad you're not posting the code, can't help. –  Anita Boerboom Sep 24 '11 at 19:09
add comment

1 Answer

Update solution is an asynchronous command. You have to wait for its completion.

When using the GUI, you have chances that the process is finished, but in PowerShell, it's not

This Microsoft social forum question has an answer that show how to wait. Basically, you have to use a function that detects the completion of the job :

$SolutionFileName = "MySolution.wsp"

$JobName = "*solution-deployment*$SolutionFileName*"
  $job = Get-SPTimerJob | ?{ $_.Name -like $JobName }

  if ($job -eq $null) 
  {
    Write-Host Timer job not found for $SolutionFileName
  }
  else
  {
    $JobFullName = $job.Name
    Write-Host -NoNewLine Waiting to finish job $JobFullName

    while ((Get-SPTimerJob $JobFullName) -ne $null) 
    {
      Write-Host -NoNewLine .
      Start-Sleep -Seconds 2
    }
    Write-Host Finished
  }

[Edit] Another simple approach is to use the legacy stsadm -o upgradesolution which runs synchronously.

share|improve this answer
    
Thanks for the answer Steve. I added the wait functionality, but I still get the same error. –  user602441 Sep 19 '11 at 19:39
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.