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 am writing Powershell script for adding my solution,activating solution and at last activation features on my SP2010 server. There are no issues in adding solution and deploying the solution. Issues is when I try to enable features with Enable-SPFeature command it doesn't find the feature on the server though through UI the features are present. I doubt that it tries too quickly while the deployment is still under its way. Is there any way to check if the deployment is complete or do I need to restart some service or something.

Please suggest

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

What you are experiencing is most likely caching.

PowerShell is keen on caching your instantiated objects, like SPWeb and SPSite, and its content, so if you run everything in one big lump you will see that for example added features wont show up.

A simple way of testing if this is the issue, try to split the script up in two. Then first execute one script, close the shell, open another and execute that.

If it runs without issues, this is a caching issue!

We have solved this by spawning new processes (Start-Process "PowerShell.exe" ....) based on folders:

010 Solutions
    10 Solution
    20 Features
020 Etc etc

Each new folder is interpreted as a new PowerShell instance.

This works well, so I would recommend a similar approach. A simpler approach would be to simply spawn a new process to execute your feature provisioning:

$command = "your commands goes here"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes)
# encoded to avoid encoding and escaping issues
# STA ensures you are running single threaded, important as most SharePoint objects isnt multi threaded
Start-Process powershell.exe -NoLogo -encodedCommand $encodedCommand -STA
share|improve this answer
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.