Add a user to the SharePoint_Shell_Access role for all SharePoint 2010 content databases

In order to use Windows PowerShell for SharePoint 2010 Products, a user must be a member of the SharePoint_Shell_Access, and you can do that via Add-SPShellAdmin cmdlet. However if user needs to work with a lot of content databases then you need to repeat this procedure over and over. Here is a simple script that will add a user to the SharePoint_Shell_Access role for all content databases.

1if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
2 Add-PSSnapin Microsoft.SharePoint.PowerShell;
3}
4cls
5$username = Read-Host "Enter username";
6Get-SPContentDatabase | ForEach-Object {Add-SPShellAdmin -UserName $username -database $_.Id}