SharePoint 2010: Get Data from SQL Server with PowerShell

SharePoint 2010: Get Data from SQL Server with PowerShell

A little script for getting data from SQL Server with PowerShell in SharePoint 2010:

 

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=SQLServer\SQLInstance;Database=DataBaseName;Integrated Security=True"
$SqlConnection.Open()
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "select * from tblMARQUET"
$SqlCmd.Connection = $SqlConnection
$dbname = $SqlCmd.ExecuteScalar()
$SqlConnection.Close()
Write-output "Database is " $dbname

PS: do not forget to change your connectionstring and commandtext

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Gokan Ozcifci edited Revision 2. Comment: Add Content

  • Ed Price - MSFT edited Original. Comment: Title; tags

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Original. Comment: Title; tags

  • Gokan Ozcifci edited Revision 2. Comment: Add Content

Page 1 of 1 (2 items)