Hi Guys
I wrote a script that checks the WIFI signal and some other stuff. I want to put that in a SQLite DB.
DB creation:
Add-Type -Path "C:\Program Files\System.Data.SQLite\2010\bin\System.Data.SQLite.dll" $cn = New-Object -TypeName System.Data.SQLite.SQLiteConnection $cn.ConnectionString = "Data Source=C:\Database\Status.db;New=True; "$cn.Open() $cm = New-Object -TypeName System.Data.SQLite.SQLiteCommand $sql = create table network_State_Polling(create_date TEXT, LAN_Name TEXT, LAN_State varchar(70), LAN_Signal varchar(50), WiFi_Name varchar(50), WiFi_State varchar(50), WiFi_Signal varchar(50), MBN_Name varchar(50), MBN_State varchar(50), MBN_Signal varchar(50)); $cm.Connection = $cn $cm.CommandText = $sql $cm.ExecuteNonQuery() $cn.Close()
To test the input of variables i did the following:
Function AddRecord ($Date, $Date1){ Add-Type -Path C:\Program Files\System.Data.SQLite\2010\bin\System.Data.SQLite.dll $cn = New-Object -TypeName System.Data.SQLite.SQLiteConnection $cn.ConnectionString = Data Source=C:\Database\Status.db $cn.Open() $cm = New-Object -TypeName System.Data.SQLite.SQLiteCommand $sql = "insert into network_State_Polling values($Date, $Date1,'test2','test3','test','test1','test2','test3','test2','test3');" $cm.Connection = $cn $cm.CommandText = $sql $cm.ExecuteNonQuery() $cn.Close() } $Date = ((Get-Date).ToString('ddMMyyyyHHmmss')) #WIFI $enabledWIFI = Get-WmiObject -Namespace "root\cimv2" -Query 'select NetEnabled from win32_networkadapter where Description = "Intel(R) Dual Band Wireless-AC 7260"' write-host "WiFi connection" if ($enabledWIFI.NetEnabled){ $wlanraw = netsh wlan show interface #$objWLAN = "" | Select-Object SSID, Signal, State ForEach ($Line in $wlanraw) { if ([regex]::IsMatch($Line," SSID")) { $objWLANSSID = $Line -Replace" SSID : ","" } if ([regex]::IsMatch($Line," Signal")) { $objWLANSignal = $Line -replace " Signal : ","" } if ([regex]::IsMatch($Line," State")) { $objWLANState = $Line -replace " State : ","" } } if ([regex]::IsMatch($objWLANSSID, "NmbsSncb")) { $State = $objWLANState write-host "SSID: "$objWLANSSID write-host "Signal: "$objWLANSignal Write-Host "" } }else { Write-Host "Device is not on WIFI or WIFI is disabled" Write-host "" }
AddRecord $Date $objWLANState.ToString()
Don't focus on the names (LAN, WIFI etc), it's just for testing.
Unfortunaly i get an error:
Exception calling "ExecuteNonQuery" with "0" argument(s): "SQL logic error or missing database
no such column: connected"
At C:\Temp\AddingLines.ps1:17 char:1
+ $cm.ExecuteNonQuery()
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SQLiteException
Connect is the value of$objWLANState.
Could somebody help me please? I have no idea what i'm doing wrong..
Thanks!
Steini46