Hi Guys,
I started learning powershell scriping recently and I noted my learning updates here for quick reference
If you are unable to add snapin to the powershell console, you may not have sufficient permissions to do the scripting.
Here are the steps to get the permissions to run the scripts.
You should have access to sharepoint shell configuration database and here is the cmdlet.
Add-SPShellAdmin -username contoso\user1
You have to perform the above step by using farm administrator privileges. The above command adds the user name specified to the Sharepoint_shell_access role on the configuration database.
If you want to give permission to a specific content database for a webapplication, specify the database parameter
Add-SPShellAdmin -username contoso\user1 -database guid
2. To get help on any command,
help Get-SPSite
3. To get examples on the cmdlet.
Get-SPSite -examples
4. To get information about the site,
Get-SPSite http://litware | select owner, Name, Description
5. To know about the features in a site collection
Get-SPFeature -site http://litware
6. To activate the features
Enable-SPFeature -identity GUID -url http://litware
7. To install the feature,
Install-SPFeature featurename
e.g Install-SPFeature MyCustomFeature
Before installing the feature, make sure that, the feature files are deployed correctly in 14 hive features folder.
8. To add the solution to the farm,
Add-SPSolution solutionname
e.g. Add-SPSolution "D:\mycustomsolution.wsp"
9. To deploy the solution to the GAC
Install-SPSolution -identity mycustomsolution.wsp -webapplication http://litware -GACdeployment
10. To update the solution
Update-SPSolution -identiy mycustomsolution.wsp -literalpath "d:\mycustomsolution.wsp" -GACdeployment
11. To uninstall the solution from the web application
Uninstall-SPSolution -identity mycustomsolution.wp -webapplication http://litware
12. To remove the solution from farm
Remove-SPSolution -identity mycustomsolution.wsp
Below is the example
Powershell script to install a feature for all the site collections in a farm with known GUID
Add-PSSnapin microsoft.sharepoint.powershell
$webapplications=Get-SPWebapplication
foreach($webapp in $webapplications)
{
$id=$webapp.id;
write-host "processing webapplication with name, id" + $webapp.Name, $id
foreach($site in $webapp.Sites)
{
$name=$site.Name;
write-host "processing site collection -" + $name
foreach($web in $site.AllWebs)
{
write-host "processing web" +$web.title
$features=$web.features;
if($web.features[GUID] -eq $null)
{
enable-spfeature -identity GUID -url $web.url -confirm:$false
}
}
}
}
I started learning powershell scriping recently and I noted my learning updates here for quick reference
- To add powershell snap-in
If you are unable to add snapin to the powershell console, you may not have sufficient permissions to do the scripting.
Here are the steps to get the permissions to run the scripts.
You should have access to sharepoint shell configuration database and here is the cmdlet.
Add-SPShellAdmin -username contoso\user1
You have to perform the above step by using farm administrator privileges. The above command adds the user name specified to the Sharepoint_shell_access role on the configuration database.
If you want to give permission to a specific content database for a webapplication, specify the database parameter
Add-SPShellAdmin -username contoso\user1 -database guid
2. To get help on any command,
help Get-SPSite
3. To get examples on the cmdlet.
Get-SPSite -examples
4. To get information about the site,
Get-SPSite http://litware | select owner, Name, Description
5. To know about the features in a site collection
Get-SPFeature -site http://litware
6. To activate the features
Enable-SPFeature -identity GUID -url http://litware
7. To install the feature,
Install-SPFeature featurename
e.g Install-SPFeature MyCustomFeature
Before installing the feature, make sure that, the feature files are deployed correctly in 14 hive features folder.
8. To add the solution to the farm,
Add-SPSolution solutionname
e.g. Add-SPSolution "D:\mycustomsolution.wsp"
9. To deploy the solution to the GAC
Install-SPSolution -identity mycustomsolution.wsp -webapplication http://litware -GACdeployment
10. To update the solution
Update-SPSolution -identiy mycustomsolution.wsp -literalpath "d:\mycustomsolution.wsp" -GACdeployment
11. To uninstall the solution from the web application
Uninstall-SPSolution -identity mycustomsolution.wp -webapplication http://litware
12. To remove the solution from farm
Remove-SPSolution -identity mycustomsolution.wsp
Below is the example
Powershell script to install a feature for all the site collections in a farm with known GUID
Add-PSSnapin microsoft.sharepoint.powershell
$webapplications=Get-SPWebapplication
foreach($webapp in $webapplications)
{
$id=$webapp.id;
write-host "processing webapplication with name, id" + $webapp.Name, $id
foreach($site in $webapp.Sites)
{
$name=$site.Name;
write-host "processing site collection -" + $name
foreach($web in $site.AllWebs)
{
write-host "processing web" +$web.title
$features=$web.features;
if($web.features[GUID] -eq $null)
{
enable-spfeature -identity GUID -url $web.url -confirm:$false
}
}
}
}
No comments:
Post a Comment