Powershell Upgrade SPFeature
In Powershell
param(
[string]$WebApplicationUrl = "http://fdi-sp2013-1",
$featureId = "6cfcd848-1f9f-4bf0-ac99-c6f2df0fc3fc"
)
##########################################################################
# DECLARATIONS
##########################################################################
#Retourne le chemin
function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Get-ScriptDirectory | Push-Location
. .\Utils.ps1
$logFileName = "{0}updateFeature.log" -f (Get-Date -Format "yyyyMMdd_HHmm");
$logFilePath = "$($currentFolder)\Logs\UpgradeFeaturePublishing$($logFileName)"
EnsureLogDirectory $logFilePath
##########################################################################
# MAIN
##########################################################################
$currentUrl = "";
try{
if ($WebApplicationUrl -eq ""){
$WebApplicationUrl = AskForWebApplicationUrl
}
$webApp=Get-SPWebApplication $WebApplicationUrl
$webApp.Sites|Foreach-Object{
$spSite=$_
WriteInfo "Site: $($spSite.Url)"
$site=Get-SPSite $spSite.Url
if($site -ne $null)
{
$feature=Get-SPFeature $featureId
if($feature -ne $null){
$featuresForUpgrade = Get-SPSite $spSite.Url | %{$_.QueryFeatures($feature.Id)}
if($featuresForUpgrade -ne $null){
WriteInfo "Old Version..."
$featuresForUpgrade.Version
$featuresForUpgrade.Upgrade($false)
WriteInfo "New Version..."
$featuresForUpgrade.Version
}
}
}
}
Write-Host -NoNewLine 'Press any key to close...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}catch{
Write-Error -Message $_.Exception.Message
Write-Host -NoNewLine 'Press any key to close...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}finally{
Pop-Location
}