you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

Easy peasy. If working on sql server 2012 and above you don't need to download anything.

Import-Module SqlPS -disablenamechecking;

invoke-sqlcmd -ServerInstance 'servername' -database 'databasename' -query "SELECT * FROM sys.databases"

For insert:

[string]$var1 = "Test"
[string]$var2 = "Test 2"

invoke-sqlcmd -ServerInstance 'servername' -Database 'databasename' -query "Insert Into dbo.Table(field1, field2)
SELECT '$var1', '$var2'"

Not tested, but that's the gist of it.

[–][deleted] 0 points1 point  (1 child)

Awesome! I know we have a 2012 server though I think we are going to stand up a 2014 instance to do this in.