PowerShell

Windows PowerShell Out-Performing Stsadm Scenario

Posted on Updated on

The Developer needs to activate a feature across 5,500 site collections. By using Windows PowerShell to run the Stsadm command, he came up with the following script to automate the work:

foreach ($site in (get-spsite -limit 5000000 -Webapplication $WebApp))
{            
 Write-Host “Activating feature ” $solutionName “on” $site.url “…”;
 Write-Host stsadm “-o activatefeature -url” $site.url “-filename” $featureFileName;
 stsadm -o activatefeature -url $site.url -filename $featureFileName
   if( $lastexitcode -ne 0 )
   {             
               Write-Host “Something went wrong activating the site feature. Exit code: ” $lastexitcode “`n”  –               ForegroundColor Red;
               $failure = $true;
               $error.Clear();
    }
}

When he ran the script in her test environment, he found it took more than 12 hours to run. The Developer then decided to look for a better way of doing things. After talking to Grant, he found out there was built-in cmdlet to do this exact task. he then tried this script:

Get-SPSite –Limit ALL –WebApplication $WebAppNameorUrl |%{ Enable-SPFeature $FeatureIdOrName –url $_.Url }

The script ran in less than one hour. Lesson learned: If Stsadm.exe can do the operation, Windows PowerShell can do it too, and generally more efficiently.

Advertisements