-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup-CIDatabase.ps1
84 lines (75 loc) · 2.37 KB
/
Setup-CIDatabase.ps1
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<#
.SYNOPSIS
Sets up a database for the Computer Inventory example.
#>
#Requires -Modules SQLUtility
# The name of the database
$databaseName = 'Assets'
$server = 'localhost\SQLEXPRESS'
# Create the database
New-SqlDatabase -Name $databaseName -Server $server
# Connect to the database
$sqlConnection = Connect-SqlServer -Database $databaseName -Server $server
# Create a table OperatingSystems
Invoke-SqlCommand `
-Command @"
CREATE TABLE OperatingSystems (
Id UNIQUEIDENTIFIER PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Version VARCHAR(255)
)
"@ `
-Connection $sqlConnection
# Create table Packages
Invoke-SqlCommand `
-Command @"
CREATE TABLE Packages (
Id UNIQUEIDENTIFIER PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
Version VARCHAR(255)
)
"@ `
-Connection $sqlConnection
# Create table Computers
Invoke-SqlCommand `
-Command @"
CREATE TABLE Computers (
Id UNIQUEIDENTIFIER PRIMARY KEY,
Name VARCHAR(255) NOT NULL,
SerialNumber VARCHAR(255),
OperatingSystemId UNIQUEIDENTIFIER
)
"@ `
-Connection $sqlConnection
# Create table ComputerPackages
# This will store the actually installed packages on a particular computer
Invoke-SqlCommand `
-Command @"
CREATE TABLE ComputerPackages (
Id UNIQUEIDENTIFIER PRIMARY KEY,
ComputerId UNIQUEIDENTIFIER NOT NULL,
PackageId UNIQUEIDENTIFIER NOT NULL,
Source VARCHAR(255),
FullPath VARCHAR(255),
ProviderName VARCHAR(255)
)
"@ `
-Connection $sqlConnection
# Create table ComputerPackagesTemp
# This is a temporary table to store the query information from a computer,
# before it is merged into the database
Invoke-SqlCommand `
-Command @"
CREATE TABLE ComputerPackagesTemp (
InventoryRunId UNIQUEIDENTIFIER,
ComputerId UNIQUEIDENTIFIER,
Name VARCHAR(255),
Version VARCHAR(255),
Source VARCHAR(255),
FullPath VARCHAR(255),
ProviderName VARCHAR(255)
)
"@ `
-Connection $sqlConnection
# Close the connection
$sqlConnection.Close()