Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am able to connect to a remote SQL Server with the instance name using PowerShell. I am using an XML file (something like a configuration file) which includes all my database details. PowerShell uses this for connection establishment.

Now I want to get all "schemas" associated with a particular database that is already defined in that XML file. How can I achieve that using Powershell scripting?

Any help would be really appreciated.

share|improve this question
    
Do you want to pull this data from the flat XML file, or the database? –  Thomas Stringer Jun 24 '13 at 10:18
    
@ThomasStringer: No..I have my databasename in an XML file. But I need to pull the schemas corresponding to that database from SQL Server. Note: I am trying this remotely. –  Vysakh Jun 24 '13 at 10:41
1  
Can you provide the format of your XML file you are using? –  Shawn Melton Jun 24 '13 at 12:52
    
What's the scope of this question? Do you need help with XML in any way, or is that just background? When you say "I want to get all "schemas"", do you just need a list of the schema names from a database? Or, do you want to access objects within each schema in the database? If so, what do you want to do with the database schema objects? –  peterk411 Nov 26 '13 at 22:28

1 Answer 1

Assuming you have a valid instance of the SMO Server object defined as $ServerObject. The following code will allow you pull the names of all schemas in the database UserDatabase01:

$Database = $ServerObject.Databases | ? { $_.Name -eq "UserDatabase01" }
$Database.Schemas | Select Name

For more information on schema properties available through SMO, see the documentation for the Schema class. Unfortunately, the version of SMO for SQL 2005 is missing a lot of properties for this class. Newer versions are backwards compatible, you may want to look into installing a newer version:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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