Wednesday, November 6, 2013

#PowerShell must for SharePoint

Some handy PowerShell commands and scripts for SharePoint and other environments.

#get sharepoint farm build version
(get-spfarm).buildversion

#conditionally load sharepoint powershell snapin, if not loaded yet
If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
{
    Write-Host
    Write-Host -ForegroundColor White " - Loading SharePoint Powershell Snapin"
    $PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
    Write-Host
}

#go to the shell path where the invoking script is located at (very handy!)
$currentFolder = Get-Location -PSProvider FileSystem
$invokedFolder = [regex]::Replace($MyInvocation.MyCommand.Definition, "\\My_Script_Name.ps1", "")
if($invokedFolder -ne $currentFolder){ cd $invokedFolder }

#show my current folder path
pwd


#add wsp package (takes fullname)
Add-SPSolution -LiteralPath (gi ./MySolution.wsp).FullName

#deploy wsp package (global or web app scope)
Install-SPSolution MySolution.wsp -GACDeployment
or
Install-SPSolution -WebApplication http://MyWebAppUrl MySolution.wsp -GACDeployment

#activate wsp package feature (specific site)
Enable-SPFeature MySolution -Url http://myurl

#update existing deployed solution
Update-SPSolution -Identity MySolution.wsp -LiteralPath (gi ./MySolution.wsp).FullName -GACDeployment

No comments:

Post a Comment