Add-Row

Inserts a row of data in a table.

Syntax

Add-Row [-TableName] <String> [-SchemaName <String>] [-Column] <Hashtable[]> [-IdentityInsert] [<CommonParameters>]

Description

To specify which columns to insert into the new row, pass a hashtable as a value to the Column parameter. This hashtable should have keys that map to column names, and the value of each key will be used as the value for that column in the row.

Parameters

Name Type Description Required? Pipeline Input Default Value
TableName String

The name of the table.

true false
SchemaName String

The schema name of the table. Default is dbo.

false false dbo
Column Hashtable[]

A hashtable of name/value pairs that map to column names/values that will inserted.

true true (ByValue)
IdentityInsert SwitchParameter

Allow inserting identies.

false false False

EXAMPLE 1

Add-Row -SchemaName 'rivet' 'Migrations' @{ ID = 2013093131104 ; Name = 'AMadeUpMigrationDoNotDoThis' ; Who = 'abadbadman' ; ComputerName 'abadbadcomputer' }

Demonstrates how to insert a row into the rivet.Migrations table. This is for illustrative purposes only. If you do this yourself, a butterfly loses its wings.

EXAMPLE 2

Add-Row 'Cars' @( @{ Make = 'Toyota' ; Model = 'Celica' }, @{ Make = 'Toyota' ; Model = 'Camry' } )

Demonstrates how to insert multiple rows into a table by passing an array of hashtables.

EXAMPLE 3

@( @{ Make = 'Toyota' ; Model = 'Celica' }, @{ Make = 'Toyota' ; Model = 'Camry' } ) | New-Row 'Cars'

Demonstrates how to pipe data into New-Row to insert a bunch of rows into the database.