Powershell: Is a SharePoint solution installed or deployed?

I was having some fun with PowerShell to talks against the SharePoint object model. I needed to know if a SharePoint solution was installed and if it was deployed. I got to the code below. Might be handy for someone to see how easy it is to get info out of SharePoint.

And the purpose I need it for? In our Macaw Solutions Factory we have a development build and a package build. Development build for SharePoint deploys everything to the bin folder of one or more web applications. Package build creates a solution package (.wsp file) that does install assemblies to the GAC. If this solutions package is deployed on the development machine, we want to detect that, because you will not see any changes after compile in a development build. The GAC assemblies have precedence over the assemblies in the web application bin folder.

So here is the code, have fun with it.

[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")

function global:Test-SharePointSolution
{
    param
    (
        $solutionName = $(throw 'Missing: solutionName'),
        [switch]$installed,
        [switch]$deployed
    )
    
    if (!($solutionName.EndsWith('.cab') -or $solutionName.EndsWith('.wsp') -or $solutionName.EndsWith('.wpp')))
    {
        throw "solution name '$solutionName' should end with .cab, .wsp or .wpp"
    }
    
    if ($installed -and $deployed)
    {
        throw "Select either the '-installed' switch parameter or the '-deployed' switch parameter, not both at the same time"
    }
    
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()
    $solutions = $farm.get_Solutions()
    $solutioncheck = $false
    foreach ($solution in $solutions)
    {
        if ($solution.Name -ieq $solutionName)
        {
            if ($deployed)
            {
                $solutioncheck = $solution.Deployed
            }
            else
            {
                # installed, is always true if we get here
                $solutioncheck = $true
            }
            break
        }
    }
    return $solutioncheck
}

Test-SharePointSolution -solutionName wikidiscussionsolution.wsp -installed
Test-SharePointSolution -solutionName wikidiscussionsolution.wsp -deployed
Published Wednesday, October 10, 2007 8:39 PM by svdoever
Filed under: ,

Comments

Friday, March 19, 2010 7:04 AM by Jayvardhan Patil

# re: Powershell: Is a SharePoint solution installed or deployed?

Thanks for the solution.

I needed some lines of it. Basically I wanted to know how can I access installed Solutions. Its objSPFarm.Solutions so simple :-)

Wednesday, November 17, 2010 7:23 AM by Tom

# re: Powershell: Is a SharePoint solution installed or deployed?

In SP 2010 you can do that with Get-SPSolution technet.microsoft.com/.../ff607754.aspx

Saturday, December 18, 2010 10:48 AM by new ipad app

# re: Powershell: Is a SharePoint solution installed or deployed?

Never underestimate your power to change yourself!

-----------------------------------

Friday, December 24, 2010 12:20 PM by ipad touch review

# re: Powershell: Is a SharePoint solution installed or deployed?

Sow nothing, reap nothing.

-----------------------------------

Sunday, January 02, 2011 10:53 PM by best ipad covers

# re: Powershell: Is a SharePoint solution installed or deployed?

-----------------------------------------------------------

"Hello there, I identified your blog in a new directory of weblogs. I dont know how your weblog came up, must are actually a typo, Your web site seems good. Have a good day."

Sunday, January 16, 2011 8:40 PM by dab radio reviews

# re: Powershell: Is a SharePoint solution installed or deployed?

I was extremely delighted to find this site.I desired to say thanks to you with regard to this excellent read!. I surely enjoyed each small bit of it and We've you bookmarked to check out new issues you article.

--------------------------------------------------------------------  

I have a <a href="ericsreviews.com/">mp3 players reviews</a> Website,i love him.Mania !You are welcome to look!

Thursday, June 30, 2011 1:12 AM by Mckinley Goodrich

# re: Powershell: Is a SharePoint solution installed or deployed?

Your writing is excellent and gives food for thought. I hope that I'll have much more time to go by way of your content. Regards. I wish that you basically publish new texts and invite you to greet me.

Leave a Comment

(required) 
(required) 
(optional)
(required)