Skip to content

Instantly share code, notes, and snippets.

@ATLPhenx
Created April 27, 2016 17:15
Show Gist options
  • Save ATLPhenx/94ebad45769ca4bbea8ef48528f7fc10 to your computer and use it in GitHub Desktop.
Save ATLPhenx/94ebad45769ca4bbea8ef48528f7fc10 to your computer and use it in GitHub Desktop.
$connectionString = "Data Source=SQLSERVER;Initial Catalog=SYSINFO;Integrated Security=SSPI;"
#Find Connection information
#Gets system information
$os = Get-WmiInfo Win32_OperatingSystem
#loads the part of the .NET Framework that’s responsible for working with databases
[assembly.reflection]::loadwithpartialname('System.Data')
#Create new connection to database
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = $connectionString
$conn.open()
#Creates sql command
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.connection = $conn
$cmd.commandtext = $query
#$cmd.executenonquery()
$queryResult = $cmd.ExecuteReader()
$conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment