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.
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.