In this recipe, we'll list all the SQL-Instances, along with the necessary credentials in a CSV file, by performing the following steps:
- Explicitly load the SqlServer module.
- Read the CSV fields using Import-CSV cmdlets.
- Start the iteration using Foreach-Object.
- Build a secure connection string with the System.Management.Automation.PSCredential class.
- Instantiate the SQL Server Microsoft.SqlServer.Management.Smo.Server class library by creating an object.
- Build the connection to the SQL instance.
- Create a subobject for the main object to create a database named PacktPub on all the defined SQL instances.
- Handle the exception using the try, catch, and finally clauses.
- Close the connection.
- Repeat the iteration until it reaches ...