So, I want to write a PS script to do what I thought was something fairly simple:
OK. So I have some preliminary code, right:
I'm not entirely sure whether anything after "$retentiondata" will work (heck, I'm not even sure if you can construct the query string that way), but I'm not getting that far.
It will not let me connect as the sa user. Tells me over and over login failed after I try $con.open(). I have confirmed the sa user's password twice.
Stuff in use: Windows Server 2008 R2 and a just-installed instance of SQL Server 2014. Now, when I installed it, it asked me if I wanted to use Windows Authentication only, to which I said, "sure!" Is my problem that answering that question in the positive has just... permanently fucked somehow any attempt to have local SQL logons? The sa account was still *there*, it was just disabled with no password, which I fixed. I confirmed sa has access to everything according to the "security" bit in SSMS -- and it's not saying access denied, but rather login failed.
What am I doing wrong here?
Code:
Foreach Thing in Things
{
Read about Thing from a table in a database
Do some stuff with the info you read
Write some results about Thing back to the database
}
OK. So I have some preliminary code, right:
Code:
$con = New-Object System.Data.SqlClient.SqlConnection("Server=10.110.0.251;Database=BackupDB;User ID=sa;Password=P@ssword1!;connect Timeout=30")
$con.open()
$instance = "TEST001"
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = ("SELECT Retention FROM BackupMetadata WHERE InstanceName = '" + $instance + "'")
$cmd.Connection = $con
$retentiondata = 0
$retentiondata = $cmd.ExecuteReader
Write-Host "Retrieved: $retentiondata"
I'm not entirely sure whether anything after "$retentiondata" will work (heck, I'm not even sure if you can construct the query string that way), but I'm not getting that far.
It will not let me connect as the sa user. Tells me over and over login failed after I try $con.open(). I have confirmed the sa user's password twice.
Stuff in use: Windows Server 2008 R2 and a just-installed instance of SQL Server 2014. Now, when I installed it, it asked me if I wanted to use Windows Authentication only, to which I said, "sure!" Is my problem that answering that question in the positive has just... permanently fucked somehow any attempt to have local SQL logons? The sa account was still *there*, it was just disabled with no password, which I fixed. I confirmed sa has access to everything according to the "security" bit in SSMS -- and it's not saying access denied, but rather login failed.
What am I doing wrong here?
ps> .\Data_Reader.ps1