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'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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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

share|improve this answer
    
Yeah this is the solution I ended up with –  Daniel Little Apr 11 '12 at 7:11
    
The issue was the farm and feature definitions were already loaded and there is no way to refresh them. –  Daniel Little Apr 11 '12 at 7:13
add comment

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

share|improve this answer
    
No it's not a timing issue –  Daniel Little Apr 11 '12 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. –  Daniel Little Apr 11 '12 at 7:28
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.