Powershell

Have used:

  1. dir
    1. dir somen* will change to somename
  2. copy-item
  3. Write-Host “Hello World”
  4. Write-Host gives you a new line
  5. Read-Host “Press a Key”
  6. $result = New-Object …
  7. To comment out use #
  8. To comment out a block use <# … #>
  9. foreach ($var in $enumerable)
    {
    <code here>
    }

Powershell against SQL

$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Data Source=(local);Initial Catalog=<dbname>;Integrated Security=True;"
$conn.Open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.connection = $conn
$cmd.commandtext = "SELECT ID, Title FROM Film.Films WHERE Title LIKE 'G%'"

$adapter = New-Object System.Data.SqlClient.SqlDataAdapter
$adapter.SelectCommand = $cmd

$dataset1 = New-Object System.Data.DataSet
$rowCount = $adapter.Fill($dataset1)

#Write-Host $dataset1.Tables[0].Rows.Count

foreach ($row in $dataset1.Tables[0])
{
Write-Host $row['Title'].ToString()
}

Tips

double-click on text with mouse selects it. Then right-click puts it in clipboard. Then go to new location in PowerShell and then right-click will paste it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: