List all SPNs in your Domain using Powershell
By peter.stilgoe
The below script lists all SPNs in your domain using Powershell (The service type is specified on the 1st line, in this case it is returning all HTTP SPNs):
$serviceType="HTTP"
$spns = @{}
$filter = "(servicePrincipalName=$serviceType/*)"
$domain = New-Object System.DirectoryServices.DirectoryEntry
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $domain
$searcher.PageSize = 1000
$searcher.Filter = $filter
$results = $searcher.FindAll()
foreach ($result in $results){
$account = $result.GetDirectoryEntry()
foreach ($spn in $account.servicePrincipalName.Value){
if($spn.contains("$serviceType/")){
$spns[$("$spn`t$($account.samAccountName)")]=1;
}
}
}
$spns.keys
This & other useful powershell scripts can be found here Useful Powershell Scripts
Sharepoint 2010: How to remove columns from content types using powershell
By peter.stilgoe
Some columns once added to a content type dont allow you to remove them, you dont got a delete button. To delete one such column from your cotent type you can use the following Sharepoint Powershell Script:
#Attach to the web and content type $web = Get-SPWeb http://fldev003/sites/pjstest/ $ct = $web.ContentTypes["Post"] #Get link to the columnn from the web $spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($web.Fields["Page Image"]) #Remove the column from the content type and update $ct.FieldLinks.Delete($spFieldLink.Id) $ct.Update() #Dispose of the web object $web.Dispose()
Sharepoint 2010 Powershell Backup Scripts
By peter.stilgoe
Sharepoint 2010 Powershell Backup Scripts
Backup a Sharepoint 2010 Farm:
Backup-SPFarm -BackupMethod Full -Directory "Destination directory" -BackupThreads 5
List all items included the Sharepoint 2010 Farm backup:
Backup-SPFarm –ShowTree
Backup a Sharepoint 2010 Site Collection:
Backup-SPSite -Identity "http://MySharepointServer/SC1/" -Path "Path and Filename"
Sharepoint: Removing illegal characters from filenames prior to bulk uploading
By peter.stilgoe
If you are doing a migration from a filesystem to Sharepoint you will more than likely come across problems uploading documents to Sharepoint that contain illegal characters in their filenames.
In Sharepoint the following characters are classed as illegal characters – & ” : * ? <> # {} % ~ / \ Tab
The + character can also cause problems & should be avoided in filenames & sitenames.
Below are some useful Powershell scripts to help you remove the illegal characters prior to uploading your documents to Sharepoint.
List all files containing a specific character (in this case ‘&’)
gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")}
Count the number of files containing a specific character (in this case ‘&’)
(gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")}).Count
Replace a specific character with another, in our case the ‘&’ with the word ‘and’
gci -rec | ? {-not $_.psicontainer -and $_.name.Contains("&")} | % {rename-item $_.fullname -newname ($_ -replace "&","and")}
More From pstilgoe
Sharepoint 2010 One Way Trust users on the trusted domain do not return any search results
By peter.stilgoe
If you have you Sharepoint 2010 Farm setup in one domain & your users are in a seperate domain using a one way trust, when they perform a search they will not return any search results. This is because the account running the app pool for the search query service is running using a domain account on the trusting domain.
This account has no rights on the domain where the users sit to determine how the search results should be security trimmed etc. My initital thought was we need to run the search query app pool account using an account on the same domain as the users which does / will work.
However a better way is to run the following powershell command:
$searchapp.SetProperty("ForceClaimACLs",1)
now run a ‘Full Crawl’ and you users should now return search results as expected over the one way trust.
You can display you Search App details with the following command:
Get-SPEnterpriseSearchServiceApplication
Note: After performing the above search alerts will be broken. If you do need search alerts you can try running your search app pool with an account from the user domain.
How to delete & create Sharepoint 2010 managed accounts using Powershell
By peter.stilgoe
To list your managed accounts use:
get-spmanagedaccount | ft username
(| ft username) returns the full text of the username
Then to delete the account use:
Remove-SPManagedAccount
press enter & enter the name of the managed account to delete
New-SPManagedAccount
create a new managed account
Set-SPManagedAccount
set a new password expiration & notication settings on a managed account
Sharepoint 2010 Content Type Hub Error – No valid proxy can be found to do this operation
By peter.stilgoe
If you have changed your URL for your Sharepoint 2010 farm you will get the error:
‘No valid proxy can be found to do this operation’
when trying to publish new content types from the content type hub.
This is because the URL in the managed meta data service application needs to be updated to reflect the new URL change. You can do this by running the following Powershell script:
Set-SPMetadataServiceApplication -Identity "Managed Metadata Application" -HubURI "http://NewSharepointURL"
More From pstilgoe
Sharepoint 2010: Create site from site template where alternate CSS url is set – unexpected error occured accessing site settings
By peter.stilgoe
When you create a site template in Sharepoint 2010 where the template is taken from a site that has an alternate CSS url set, you find on the newly created site that when you try & access ‘Site Settings’ or ‘View all site content’ you get the ‘An unexpected error occured’.
In your logs you get something like:
System.Web.HttpException: Error executing child request for /sites/SiteName/Style Library/site-style.css
This appears to be a bug, you can fix the site by running the following Powershell script:
$w = Get-SPWeb http://YourServer/YourWeb; $w.AlternateHeader = $null; $w.Update()
More From pstilgoe
Sharepoint 2010: Database doesnt exist but sill appears in Central Admin –> Manage Databases Upgrade Status
By peter.stilgoe
If you have deleted your database in SQL but they sill appear in Central Admin –> Manage Databases Upgrade Status, you can use the following Powershell script to remove them:
$db = Get-SPDatabase | where{$_.Name -eq "YourDatabaseName"}
$db.Delete()
SharePoint 2010: BCS External List Throttling
By peter.stilgoe
In Sharepoint 2010 when you are returning rows from an external datasource using External Content Types & External Lists the defaul throttling is set to 2000 rows.
If your datasource is trying to return more than this you will get an error on you external list saying this webpart cannot be displayed etc.
If you have logging turned on for Business Connectivity Services in Central Admin -> Monitoring -> Diagnostic Logging you will see errors similar to this in your Sharepoint Logs:
Error while executing web part: Microsoft.BusinessData.Runtime.ExceededLimitException: Database Connector has throttled the response. The response from database contains more than ’2000′ rows. The maximum number of rows that can be read through Database Connector is ’2000′.
You can change these throttle limits using the following powershell script:
$bdcProxy = Get-SPServiceApplicationProxy | where {$_.GetType().FullName -eq (‘Microsoft.SharePoint.BusinessData.SharedService.’ + ‘BdcServiceApplicationProxy’)}
$dbRule = Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $bdcProxy
Set-SPBusinessDataCatalogThrottleConfig -Identity $dbRule -Maximum 5000 -Default 5000
Sharepoint 2010: Adding a new managed account from different domain errors with access denied
By peter.stilgoe
For example you are running Sharepoint 2010 in the a 1 way trust environment & you want to add a new managed account to your Sharepoint farm from your internal domain. This should be fairly simple by going Central Admin –> Security –> Configure Managed Account –> Register Managed Account
User name: domain\accountname
Password: *********
However no matter what I tried doing this in cental admin always returned the error:
An error occurred while getting information about the user
To get round this you need to add the account using powershell.
- Log onto you server using an account from your internal domain (you need to do this so it can retrieve the info it needs from this domain)
- In powershell
$cred = Get-Credential
Now a login prompt will pop up, enter the managed account details here you are wishing to add domain\username, enter password & click OK
- Now enter
New-SPManagedAccount –Credential $cred
Your managed account will now be added, you can check this in central admin or powershell using
Get-SPManagedAccount
Sharepoint 2010: Deleting orphaned service (web) application pools
By peter.stilgoe
When deleting & recreating Sharepoint service applications you sometimes get old application pools showing in your drop downs. To delete these orphaned application pools:
Remove-SPServiceApplicationPool -Identity "Orphaned SharePoint Service Application Pool Name"
To list you application pools:
Get-SPServiceApplicationPool | select Id, Name
Sharepoint 2010 – Cannot delete service application from Central Admin
By peter.stilgoe
When trying to delete a service application in Sharepoint 2010 from the central admin, sometimes you will find it just stays on the ‘processing’ window for hours (if you wait that long).
If it does you can try & delete the service application using Powershell:
Remove-SPServiceApplication
If that command doesnt work you can force the deletion by using STSADM:
STSADM -o deleteconfigurationobject -id {ID}
The above STSADM command is not documented by Microsoft (or doesnt seem to be)
SharePoint 2010 CU upgrade error – keyword not supported failoverpartner
By peter.stilgoe
When applying updates to your Sharepoint 2010 farm you may get the following error in the Sharepoint Configuration Wizard:
An exception of type System.ArgumentException was thrown. Additional exception information: Keyword not supported ‘failoverpartner’.
This means youve got mirroring enabled on your Sharepoint databases and Sharepoint CU updates dont install on mirrored databases.
To find out what sharepoint databases are mirrored/failover you can use the following powershell command:
get-spdatabase | select name, failoverserver
You can turn off the failover for you content databases in central admin aswell as your service application databases. However all other databases need to be turned on & off using powershell.
To Turn Off Mirroring /Failover on your database:
$database = Get-SPDatabase | where { $_.Name -eq "ASharePointDB" }
$database.AddFailoverServiceInstance("")
$database.Update();
To Turn On Mirroring /Failover on your database:
$database = Get-SPDatabase | where { $_.Name -eq "ASharePointDB" }
$database.AddFailoverServiceInstance("FailoverSQLServerName\OptionalInstanceIfUsed")
$database.Update();
Sharepoint 2010 Service Application Database Trying To Connect To Different Database ID – Cannot complete this action as the Secure Store Shared Service is not responding
By peter.stilgoe
Had a strange problem when creating a new Secure Store Service Application, the wizard would complete but when you click ‘manage’ you would get an error saying –
‘Cannot complete this action as the Secure Store Shared Service is not responding. Please contact your administrator’
After looking at the event logs it was failing with an error:
Cannot open database “Secure_Store_Service_DB_edb5686a-ff41-4457-903a-4ff09xxxxxx” requested by the login. The login failed. Login failed for user ‘XXXXXXX\FarmAcct’.
After lots of head scratching I notice that the db the Secure Store Service App wizard was creating in Central Admin was a different database to the one giving the connection error in my event viewer.
I tried to create a new service app & renamed the DB to the name that it was trying to connect to but I would then get an error message saying this database already existed, even though it didnt exist in SQL Management Studio.
It was trying to connect to an orphaned secure store service DB which must have been created at an earlier time, which I verified by looking here:
http://CentralAdminURL/_admin/DatabaseStatus.aspx
To cut a long story short you can use this powershell script to remove any orphaned Sharepoint 2010 Service Application databases
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq
'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
Get-SPDatabase | Where{$_.Exists -eq $false} | ForEach {$_.Delete()}
I found the script at http://www.sharepointusecases.com/index.php/2010/12/how-to-remove-renamed-sharepoint-2010-service-app-databases/
More From pstilgoe
Sharepoint 2010: The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service
By peter.stilgoe
When trying to publish a page or start a workflow you may get the following error:
“The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service”
To configure the State Service by using the Farm Configuration Wizard
1) On the Central Administration Web site, click Configuration Wizards.
2) On the Configuration Wizards page, click Launch the Farm Configuration Wizard.
3) On the first page of the Farm Configuration Wizard, click Start the Wizard.
4) On the services configuration page, in the Services section, select the State Service check box.
5) Click Next.
6) Complete any other configuration steps for the server farm.
7) On the final page of the Farm Configuration Wizard, click Finish.
NOTE: If the State Service check box is unavailable, the State Service is already configured. To make changes to the configuration you must use Windows PowerShell.
For further information:
http://technet.microsoft.com/nl-nl/library/ee704548%28en-us%29.aspx



February 13th, 2012
