Category Archives: Powershell

SharePoint 2013 Databases without the GUID

When you configure SharePoint 2013 it will create the SharePoint_AdminContent database with a GUID at the end. To keep my database names clean I searched for a solution.

To be able to set the name of the database you will have to perform the configuration with PowerShell.

Take the following steps:

1. Open SharePoint 2013 Management Shell as Administrator.

2. Type the following:

New-SPConfigurationDatabase -DatabaseName BETA_SP2013_Config –AdministrationContentDatabaseName BETA_SP2013_AdminContent –DatabaseServer SP2013DB -FarmCredentials (get-credential)

3. You will get a pop-up to fill in the farm credentials. Fill in the account you want to use to run central administration under. When you filled in the account the management shell will also ask you to fill in the passphrase for joining servers to your farm.

4. Install the help collection files by running the following script.

Install-SPHelpCollection –All

5. Initialize the SharePoint Security by running the following script.

Initialize-SPResourceSecurity

6. Register the SharePoint Services by running the following script.

Install-SPService

7. Create central administration by running the following script.

New-SPCentralAdministration -Port 5555 -WindowsAuthProvider “ntlm”

8. Install the application content by running the following script.

Install-SPApplicationContent

9. When everything is done. You performed the steps the configuration wizard does for you. To be absolutely sure that everything is configured run the configuration wizard.

 

After these steps SharePoint is configured with a clean database name!

Almost all other SharePoint databases can be named trough the UI only the Search Service Application and the Usage service create there own databases. The solution is to also create these services  with PowerShell.

In other for you to create the Search Service Application you can use the script below (You only have to change the arguments on the top).

$databaseServer = "SP2013DB"
$ServiceAppPool = "SharePoint Services Application Pool"
$IndexLocation = "C:\SP2013_Search"
$SearchServiceApplicationName = "Search Service Application"
$server = "CLAY"

Write-Host "Setting up Search"

Start-SPEnterpriseSearchServiceInstance $server
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $server

$searchApp = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceApplicationName -ApplicationPool $ServiceAppPool -DatabaseServer $databaseServer -DatabaseName "BETA_SP2013_Search"
$searchInstance = Get-SPEnterpriseSearchServiceInstance $server

$ssa = Get-SPEnterpriseSearchServiceApplication 

Write-Host "Setup Topology"
$ssa.ActiveTopology
$clone = $ssa.ActiveTopology.Clone()

New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstance
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstance 
New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchInstance 
New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchInstance -RootDirectory $IndexLocation
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstance

$clone.Activate()

$ssa | get-SPEnterpriseSearchAdministrationComponent |  set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance  $searchInstance


Write-Host "Setup Proxy"
$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$SearchServiceApplicationName Proxy" -SearchApplication $SearchServiceApplicationName > $null

Write-Host "Done"

 

You need to take the steps below to create the Usage Service Application:

1. Get the Usage Service.

$serviceInstance = Get-SPUsageService

2. Create the service application.

New-SPUsageApplication -Name "Usage Service Application -DatabaseServer SP2013DB -DatabaseName "BETA_SP2013_UsageDB" -UsageService $serviceInstance > $null

3.  Get the proxy off the application and provision it.

$usa = Get-SPServiceApplicationProxy | where {$_.TypeName -like "Usage*"} 
$usa.Provision()

Windows PowerShell command builder

Today I found something interesting on the internet which I think can help everyone who is working with SharePoint. Microsoft has built a Silverlight application that can be used to build PowerShell commands.
 
Windows%20Powershell%20Builder
 
 
Microsoft says:
 
the Windows PowerShell Command Builder enables IT professionals and power users to visually assemble commands related to SharePoint 2010 Products and Office 365 on a Design Surface in a browser and take those commands to their respective products. The Windows PowerShell Command Builder provides an intelligent user experience. After you drag a verb or noun object on the Design Surface, the interface will hide either the verbs or nouns that are not associated with the verb or noun placed on the Design Surface. After you construct a command, you can copy the command to Windows PowerShell script, the SharePoint 2010 Management Shell, or other desired location to be saved or executed.
 
You use the tool by clicking here. You can also install it on your desktop by right clicking on the application.
 
Microsoft also released some guides to get started with the tool:

Deleting a Project Service Application within SharePoint 2010

A couple of days ago I deleted my Project Server Web application because I wanted to recreate it.

When I tried to create a new Project Web App Site I got the following messages:

  • The database specified is already used by another project server. Enter a different server or database name and try again.

projectserver

The first idea that I came up with was deleting the databases from the database server. After deleting the databases I retried my action but the problem was still there.

The next thought that came up in my head was deleting the Project Service Application. I pressed delete on the Manage Service Application Page and got the following error message:

  • Service application cannot be deleted due to existing project sites.

errordeleteprojectserviceapplication

The problem is with the Project Service Application. The Project service application remains a connection with a specific site collection even If you delete the web application or the specific site collection. The only thing you can do to delete the connected site collection (that does not exist anymore) from the Project Service Application by using PowerShell.

First you will have to use PowerShell to retrieve a collection of the sites that are referenced with the service application. Get the ID of the reference you want to remove and than remove that reference .

Let take the first step, get the service application and print the site collections.

$svApp = Get-SPServiceApplication -Name "Project Web App Service Application"
$svApp.SiteCollection 

This will get a complete list of all the associated site collections:

powershelloutcome

Next you can copy the ID and remove it by using the following PowerShell command:

$svApp.SiteCollection.Remove("a09c6964-efc2-4917-9448-ce86d0bc95d3")

And now you can remove the Service Application or recreate the site collection. To remove the service application by using powershell use the following command:

Remove-SPServiceApplication $svApp -RemoveData

Provisioning My Sites SharePoint 2010

In certain scenarios you would like to provision the My Sites of the users before you go live with the environment. Within SharePoint 2010 you have got several options to complete this task.

One of the options is to create a PowerShell script. With PowerShell you have the ability to read through the user profile store that is used for a certain web application and create a My Site for each profile in the profile store. If you want to use PowerShell to accomplish this task you can use the following script:

[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") 
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") 
 
$siteurl = "http://yoursiteurl"     
 
$site = New-Object Microsoft.SharePoint.SPSite($siteurl) 
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site) 
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) 

$upm.Count;
$profiles = $upm.GetEnumerator()
foreach ($userobject in $Profiles ) {

    # start loop here 
    $user = $userobject.item("AccountName")
    $user
    if ($upm.UserExists($user)) { 
        $profile = $upm.GetUserProfile([string]$user) 
     
        # there are other exceptions you can catch, check out the UserProfiles class 
        trap [Microsoft.Office.Server.UserProfiles.PersonalSiteExistsException] { 
            Write-Host "personal site already exists for $user" 
            continue 
        } 
        $profile.CreatePersonalSite();
        trap {
        Write-Host "Error creating site for $user" -ForeGroundColor Red
        continue
        }
        Write-Host "Personal site for $user created..." -ForeGroundColor Green
    }  else { 
      Write-Host: "user $user did not exist" 
    } 
}
# end loop here 
$site.Dispose() 

The second option you have is creating a C# application. This c# application will to exactly the same as the powershell script. The method to create the MySites is displayed below.

private static void CreateMysite(string siteUrl)
        {
            using (SPSite site = new SPSite(p_2))
            {
                SPServiceContext serviceContext = SPServiceContext.GetContext(site.WebApplication.ServiceApplicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
                UserProfileManager profileConfigManager = new UserProfileManager(serviceContext);
                try
                {
                    long count = profileConfigManager.Count;

                    for (int i = 1; i <= count; i++)
                    {
                            UserProfile profile = profileConfigManager.GetUserProfile(i);
                            Console.WriteLine(profile.DisplayName);
                            profile.CreatePersonalSite(1043);
                    }
                }
                catch (UserNotFoundException) {}
                catch(PersonalSiteExistsException){}
            }
        }

In the application above I catch the UserNotFoundException this is done because it can occur that a user profile is present but not the user.