-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1002.ps1
More file actions
44 lines (35 loc) · 1.5 KB
/
1002.ps1
File metadata and controls
44 lines (35 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#Change these settings as needed
#MS Access 2007 Data Components required
$connString = 'Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=2;RetrieveIds=Yes; DATABASE=http://sharepoint.acme.com/;LIST={96801432-2d03-42b8-82b0-ac96ca9fea8a};'
#See http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!275.entry for instructions on obtaining list GUID
$qry = 'Select Title,Notes,CreateDate, Modified, Created from list'
#Create a table in destination database with the with referenced columns and table name.
$sqlserver = 'Z002\SQL2K8'
$dbname = 'SQLPSX'
$tblname = 'splist_fill'
#######################
function Get-SPList
{
param($connString, $qry='select * from list')
$spConn = new-object System.Data.OleDb.OleDbConnection($connString)
$spConn.open()
$cmd = new-object System.Data.OleDb.OleDbCommand($qry,$spConn)
$da = new-object System.Data.OleDb.OleDbDataAdapter($cmd)
$dt = new-object System.Data.dataTable
$da.fill($dt) > $null
$dt
} #Get-SPList
#######################
function Write-DataTableToDatabase
{
param($destServer,$destDb,$destTbl)
process
{
$connectionString = "Data Source=$destServer;Integrated Security=true;Initial Catalog=$destdb;"
$bulkCopy = new-object ("Data.SqlClient.SqlBulkCopy") $connectionString
$bulkCopy.DestinationTableName = "$destTbl"
$bulkCopy.WriteToServer($_)
}
}# Write-DataTableToDatabase
#######################
Get-SPList $connString $qry | Write-DataTableToDatabase $sqlserver $dbname $tblname