0

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
3
  • 1
    Please update your question with the code which is used in the feature. Are you using SPContext? Sep 17, 2011 at 7:49
  • There is far too much code in the feature to paste here. I am not using SPContext.
    – user602441
    Sep 19, 2011 at 19:41
  • Too bad you're not posting the code, can't help. Sep 24, 2011 at 19:09

1 Answer 1

1

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.

1
  • Thanks for the answer Steve. I added the wait functionality, but I still get the same error.
    – user602441
    Sep 19, 2011 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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