powershell 数据库连接Powershell snippits
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 数据库连接Powershell snippits相关的知识,希望对你有一定的参考价值。
function Invoke-SQL {
param(
[string] $dataSource = $(throw "Please specify a datasource."),
[string] $database = $(throw "Please specify a database."),
[string] $sqlCommand = $(throw "Please specify a query.")
)
$connectionString = "Data Source=$dataSource; " +
"Integrated Security=SSPI; " +
"Initial Catalog=$database"
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
$connection.Open()
$adapter = New-Object System.Data.sqlclient.sqlDataAdapter $command
$dataset = New-Object System.Data.DataSet
$adapter.Fill($dataSet) | Out-Null
$connection.Close()
$dataSet.Tables
}
$sqlServerName = "SPF-SV-DYNDVDB1"
###############
#Get any active output actions with attachments. Catalog them
###############
$database = "CaseTrakker"
$sSQL = "SELECT TOP 10 * FROM ct_note"
$dataTable = Invoke-SQL -dataSource:$sqlServerName -database:$database -sqlCommand:$sSQL
#Query the database to get any attachemnts
foreach ($row in $dataTable | Where {$_.object_type -eq "111"} | Sort-Object ct_id)
{
Write-Host $row["ct_id"]
}
Write-Host "DONE"
以上是关于powershell 数据库连接Powershell snippits的主要内容,如果未能解决你的问题,请参考以下文章
Create AD Users by Powershel_v1.0
使用powershell提权的一些技巧
内网渗透之Windows反弹shell
命令行转义PowerShell的单引号
在远程服务器上使用 PowerShell 安装证书
是否可以/如何使用某些 cmdlet 停止 powershell?