Q: PS to list all schemas This may be simple enough.But since I am new to powershell handling sql script,I am here with a question.
After getting connected to a database how can we retrieve all the schema's listed in that particular database? Can anyone provide me a sample script of achieving this?

A: # I like to use SMO. There are other ways, arguably just as good.
# You need to make sure that the SMO library is loaded. 
# If it already is loaded, you don't need this line. 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null 

# I'm using integrated security. 
# If you aren't, you will need to add a username and password here.
# substitute your server name in place of localhost 
$server = New-Object ([Microsoft.SQLServer.Management.SMO.Server]) "localhost"

# Substitute your database name in place of 
AdventureWorks $Database = $server.Databases | where {$_.Name -match "AdventureWorks"}
$Database.Schemas | Format-Table Name

# if you want to see schemas in all databases in one list, this should work 
$server.Databases.Schemas | format-table Parent,Name

