I am trying this in a test lab.
I am new to powershell and SQL but trying to get into it. I am just trying to get some database from SEPM SQL, and this is what I have in my powershell script so far. The result is nothing, no errors, either.
My goal is just to connect to the database and display some sample data either on screen or in a text file. Any help is appreciated.
$datasource = "localhost"
$user = "Username"
$pwd = "Password"
$database = "sem5"
$connectionstring = "server=$datasource;uid=$user;pwd=$pwd;database=$database;Integrated Security=False;"
$connection = New-Object System.Data.SqlClient.SqlConnection
$connection.ConnectionString = $connectionstring
$connection.open()
$query = "SELECT computer_name FROM SEM_COMPUTER"
$command = $connection.CreateCommand()
$command.Commandtext = $query
$result = $command.ExecuteReader()