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


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

  • Yeah this is the solution I ended up with 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. Apr 11, 2012 at 7:13

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

  • No it's not a timing issue 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. 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.

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