Add-SPShellAdmin : Some or all identity references could not be translated.

Recently I experienced an error while trying to give SPShellAdmin access to an administrator. The admin was supposed to be added to a new content database in the SharePoint 2010 farm.

The steps I took are:

1. Opened SharePoint PowerShell and ran the following command to get the DatabaseID:


Copied the databaseID for the db I was going to add the user to.

2. Ran the following command to add the user:

Add-SPShellAdmin -UserName domain\username -database xxxxxx-c69-358e-4fc6-82a2-yyyyyyyy

3. Got the following error:

Add-SPShellAdmin : Some or all identity references could not be translated.
At line:1 char:17
+ Add-SPShellAdmin <<<<  -UserName domain\username -database xxxxxx-c69-358e-4fc6-82a2-yyyyyyyy    + CategoryInfo          : InvalidData: (Microsoft.Share…AddSPShellAdmin:
   SPCmdletAddSPShellAdmin) [Add-SPShellAdmin], IdentityNotMappedException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletAddSPShe

Well that the long and short of it tried all sort of combinations for try to get past the error but did not want to run the stsadm command as suggested by another post.


So here is the bit where I had to find an alternate solution. Remeber the user was already an aministrator and wanted to ShellAdmin access to the new content database.

1. Connect to the SQL Server that is hosting the content database.

2. Navigate to Security folder > Logins > Right click and Add the user if not user does not already exisit.

3. If the user exisits under Logins > RIght click the userID and select properties > Under User Mapping > Select the content Database and select “Public” role > Click on OK. Do not select “SharePoint_Shell_Access” at this stage.

4.  Expand the SharePoint content database > Exapand Security folder > Expand Users folder > Right click and select Properties of user > Under Database role membership check “SharePoint_Shell_Access” and click OK.

5. Open PowerShell and type the command:

Get-SPShellAdmin -database  xxxxxx-c69-358e-4fc6-82a2-yyyyyyyy 

You should not get the new user listed under the Shell Admin.

Drop a feedback if this has saved your life. Always good to hear from the SharePoint world.


PowerShell Move (Move-Item) files to designated folders based on CSV file

Recently I had to move over 5000 documents to their respective folders.


There there two columns in a csv file. First column contains folder name and second column the filename. The files had to be moved to individual folders. There can be multiple documents per folder. You need to ensure that the folders have been created in the $dir location.

#PowerShell script to create folder

Set-Location “D:\Export\Files”

$Folders = Import-Csv D:\folders.csv -Header folders

 ForEach($Folder in $Folders) {

 New-Item $Folder.folders -type directory


 #Here is the PowerShell script for moving the files in required folder:

$text = Import-Csv “D:\InputFile.csv” 

$dir = Get-ChildItem D:\Export\Files

 foreach($item in $text ){

 foreach ($folder in $dir) {

#where Package is the name of the column in the csv file and FileName the name of #second column in the input csv file

 if($item.Package – eq $Folder.Name){

 $sourcefile = “D:\Export\” + $item.Filename 

$target = “D:\Export\Files\” + $folder.Name


Write-Host“Folder $item.FileName moved sucessfully to $target”-ForegroundColor Green




NServiceBus replay error queue from remote server

Here is an approach for playing NServiceBus error queue from Remote server. Quite often this is required if the operation team does not have access to teh Messaging server or you have a Distributor setup. This setup uses references to ReturnToSourceQueue.exe tools that is supplied from NServiceBus.

Save the command below in a .ps1 file and run it from Remote server. Remeber you need to have permission to run PowerShell in local server and Read/Write permission to the Error qs in the remote server.

param (

[Parameter(Mandatory=$false, HelpMessage=‘-Computername – The Servername for the Powershell session.’)]


[Parameter(Mandatory=$false, HelpMessage=‘-Errorqueuename – The name of the Error Queue to be replayed.’)]


[Parameter(Mandatory=$false, HelpMessage=‘-Path – The path location to the ReturnToSourceQueue.exe.’)]



##### check the the server, error queue name and Path exists #####

Write-Host “Checking Server: “$Computername;

Write-Host “Checking Error Queue: “$Errorqueuename ;

Write-Host“Checking Path: “$Locationpath ;

##### creates a remote session on the Servercomputer #####

$sessiontem = new-pssession-computername$Computername;

##### change directory to the location of the ReturnToSourceQueue.exe #####

Invoke-Command -Session $sessiontem {cd“C:\install\nServiceBus\tools”};

##### invoke the command to call replay the error queue #####

Invoke-Command -Session $sessiontem {.\ReturnToSourceQueue.exe error all};

##### close pssession #####

Remove-pssession $sessiontem;

##### completed #####

Write-Host $Errorqueuename“queue replayed successfully.” ;