Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 SMO commands using PS
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TRACEYSQL
Aged Yak Warrior

594 Posts

Posted - 01/03/2014 :  18:24:31  Show Profile  Send TRACEYSQL an ICQ Message  Reply with Quote
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SqlServer.Smo”) | out-null
## Connect to the SQL Server and get the Stored-procedures
$server = new-object(‘Microsoft.SqlServer.Management.Smo.Server’) “MYSERVERNAME”
$db = $server.Databases["MYDATABASE"]

$dbcmd = @"
SELECT [MYCOLUMN]
FROM [dbo].[MYTABLE]
"@

$ds = $db.ExecuteWithResults($dbcmd)

$dt = $ds.Tables[0]

#IF I just do $dt i see the value of MYCOLUMN

#IF I do below i only get

$dt | Format-Table -Property DatabaseName, TableName, RowCount -Autosize

#Database Name TableName ---these column names and nothing else.

Any ideas what I am misisng
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000