Blog de Augusto Simoes (MVP)

Sharepoint, OCS, Windows Server ...

Augusto Simoes

Consultant Infrastructure & Trainer

Ma mission est de concevoir les architectures de messageries unifiés et collaboratives afin d'accompagner nos clients vers ces nouvelles technologies.

  • Microsoft Certified Trainer
  • Microsoft Certified Systems Engineer
  • Microsoft Certified Technology Specialist :SharePoint, WSS, OCS 2007, Vista, Windows 2008
  • Microsoft Certified Database Administrator SQL 2000, 2005


MVP Logo


MyTag

Mon Profile Chez Microsoft



 

 

RecentComments

Comment RSS

[PowerShell] Exécuter un Insert Into dans une table SQL

Voici un simple script PowerShell permettant de faire un simple INSERT INTO dans une table dans SQL Serveur.

#################################################################
#             Change data for your connection String            #
#################################################################
$Serveur="PCSEVENAS\SQLEXPRESS" # Change for your Server Name   #
$Database="MyDatabaseTest" # Change for your Database Name      #
$Table="dbo.MyFirstTable" # Change for your Table Name          #
#################################################################
$SQLConnect = new-object system.data.sqlclient.sqlconnection
$SQLConnect.connectionstring = "Server=$Serveur;database=$Database;trusted_connection=yes;"
# Open Connection to SQL Server
$SQLConnect.Open()
# End Connection String

# Loop for Insert Into
for ($C1=30;$C1 -lt 40;$C1++)
{
#################################################################
#            Change your Columns Name [c1] [c2]                 #
#################################################################
$Requete = "INSERT INTO $Table ([c1],[c2])VALUES($C1,'Toto$C1')"
#################################################################
$command = New-object system.data.sqlclient.SqlCommand 
$command.connection = $SQLConnect
$command.commandtext = $Requete
$command.Executenonquery()
}
# End Loop

# Close Connection to SQL Server
$SQLConnect.Close()

Voila le résultat dans SQL Server Management Studio:

SSMS_INSERT_PowerShell


Bookmark and Share

Posted: Jan 06 2010, 12:08 by collaboration | Comments (0) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5