Thursday, June 14, 2012

powershell activate feature sharepoint

  write-output $_ 
  exit 1 
# define variables for script
$webApp  =$args[0]

# 1. check to ensure Microsoft.SharePoint.PowerShell is loaded
    $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
    if ($snapin -eq $null) 
        Write-Host "Loading SharePoint Powershell Snapin"
        Add-PSSnapin "Microsoft.SharePoint.Powershell"

# 3. Add solution to SharePoint Solution Store

        Write-Host "Getting Faeture for ID" + $featureId   

 $feature= Get-SPFeature -Identity $featureId
    $site=Get-SPSite $webApp 

     $sitefeature= $site.Features[$feature.Id]
  if($sitefeature -ne $null)
   Write-Host "Feature Already activated in this site"
   Write-Host "Disabling the Feature"
         Disable-SPFeature -Identity $feature.Id -Url $webApp  -confirm:$false -force
       Write-Host "uninstalling the Feature"
         uninstall-spfeature -identity $feature.Id  -confirm:$false -force

   Write-Host "installing the Feature"
   install-SPFeature -Path $feature.RootDirectory -confirm:$false -force
       Write-Host "Enabling the Feature"
  Enable-spfeature -Identity $feature.Id -Url $webApp -confirm:$false -force 
Write-Host "Done"

No comments:

Post a Comment