If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.
[string]$datasource = 'sqlserver'
[string]$database = 'databasename'
[string]$connectionString = "Data Source=$dataSource;Integrated Security=SSPI;Initial Catalog=$database"
$conn = $new-object system.data.sqlclient.sqlconnection ($connectionString)
[system.data.sqlclient.sqlcommand]$cmd = new-object system.data.sqlclient.sqlcommand
[system.data.sqlclient.sqldataAdapter]$sqlAdapter = new-object system.data.sqlclient.sqldataadapter
[system.data.datatable]$dt = new-object system.data.datatable
try {
[void]$conn.open()
$cmd.Connection = $conn
$cmd.Commandtext = 'Select * From Table1'
$sqlAdapter.SelectCommand = $cmd
$sqlAdapter.Fill ($dt) | out-null
foreach ($record in $dt.rows) {
$TempVar1 = $record.Name
$TempVar2 = $record.VersionNumber
$TempVar1 ; $TempVar2
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Here's the full code, try this:
Open in new window