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.
- Reset IIS
- Disable Features
- Uninstall Solution
- Remove Solution
- Delete Lists
- Add Solution
- Install Solution
- Enable Features