2

I'm currently writing a powershell script which upgrades a set of solutions then a set of features from those solutions.

After the solution upgrades everything looks great until I Call QueryFeatures which proceeds to return an empty result set.

 # This is just sample code
 $site.QueryFeatures((Get-SPFeature | Where { $_.DisplayName -match "$FeatureName" } | Select -First 1).Id, $true)

I've tried disposing the site before use then creating a new site with new-object, and even Clearing the Object Model Cache. The only thing that works is to open a new powershell window and issuing the same command.

However this is part of a long running script so this obviously isn't the best solution. Has anyone run into this issue before?

2 Answers 2

3

It's a common issue when writing deployment scripts for SharePoint in PowerShell that often you need to spawn a new PowerShell in order to:

  • Get rid of cahcing
  • Get a clean AppDomain without old version of dlls loaded

The version of the dlls is going to be your next problem as I assume you're going to call Upgrade on the returned features, which might want to call into a FeatureReceiver which needs to be the new version.

So it's common to write the main script as a series of:

powershell -noexit -command &'Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;substep.ps1' -sta

2
  • Yeah this is the solution I ended up with Commented Apr 11, 2012 at 7:11
  • The issue was the farm and feature definitions were already loaded and there is no way to refresh them. Commented Apr 11, 2012 at 7:13
0

Could be a timing issue. Stick a 60 second wait in your script just before this point and see if that helps

2
  • No it's not a timing issue Commented Apr 11, 2012 at 7:11
  • You should also poll, not just wait 60s, as a async action could take more or less than 60s especially over a large farm. Commented Apr 11, 2012 at 7:28

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.