I'm creating a script to get the CNAME and port that the SharePoint servers use. Is there an out of the box way of doing this? I know that there are plugins I can use but would prefer not to.

1 Answer 1


It is technically possible for each site collection in the farm to be on different SQL servers so the closest you can probably get is to look at the iterate through all of the site collections on all of the web apps and look at SPSite.ContentDatabase.Server property.

An alternative way to get this is to iterate through the webApplications on the farm and then simply pull the information you want from the databases in the .ContentDatabases collection of each SPWebApplication.

Which route you take depends on the specific needs of the script though the second approach would probably be faster, particularly on a large farm.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.