globalscape/powershell/EFTPowerToolsPS/EFTPowerToolsPS/EFT.Sqlite.Invoke-NoQuery.ps1

34 lines
1.1 KiB
PowerShell

[CmdletBinding()]
Param(
[Parameter(Position = 1, Mandatory = $true, HelpMessage = "Enter a workspace db file")]
[String] $WorkspacesDbFile = "Workspaces.db",
[Parameter(Position = 1, Mandatory = $true, HelpMessage = "Enter a table name")]
[String] $query = "select * from Site",
[Parameter(Position = 1, Mandatory = $false, HelpMessage = "Enter a table name")]
[hashtable] $params = $null
)
# Get all Ids to Text
#.\EFT.Sqlite.Invoke-NoQuery.ps1 -query "insert into site (id, ws_enabled, ws_allowSharingToExistingUsersOnly) Values (@id, 1,0)" -params @{"@id" = [guid]::new("edbda119-46e7-4ad5-b143-a1806955d7d5") ;}
Add-Type -Path "System.Data.SQLite.dll"
$DbFile = Resolve-Path $DbFile
$conn = New-Object -TypeName System.Data.SQLite.SQLiteConnection
$conn.ConnectionString = "Data Source=$DbFile"
$conn.Open()
$command = $conn.CreateCommand()
$command.CommandText = $query
if ($null -ne $params) {
foreach ($key in $params.keys ){
Write-Verbose "$($key) = $($params[$key])"
$null = $command.Parameters.AddWithValue($key, $params[$key]);
}
}
[Int32]$command.ExecuteNonQuery()
$conn.Close()