Initialize-WOLDatabase.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

<#
 
  Create WOL Database
 
#>


$DBDesign = @(

    'CREATE TABLE Computers (
         Computer TEXT COLLATE NOCASE
                  UNIQUE,
         MAC TEXT COLLATE NOCASE
                  UNIQUE
     );'


)

If ((Test-Path $env:ALLUSERSPROFILE\PSWakeOnLAN) -eq $False)  {

    New-Item -Path $env:ALLUSERSPROFILE\PSWakeOnLAN -ItemType Directory -Force | Out-Null

}

If ((Test-Path $env:ALLUSERSPROFILE\PSWakeOnLAN\WOLDatabase.db3) -eq $False) {

    Add-Type -Path $PSScriptRoot\System.Data.SQLite.dll

    $DBConnect = New-Object -TypeName System.Data.SQLite.SQLiteConnection
    $DBConnect.ConnectionString = "Data Source = $env:ALLUSERSPROFILE\PSWakeOnLAN\WOLDatabase.db3"
    $DBConnect.Open()

    $SQL = $DBConnect.CreateCommand()
    $SQL.CommandText = $DBDesign
    $SQL.ExecuteNonQuery() | Out-Null

    $SQL.Dispose()
    $DBConnect.Close()

}