2014-10-30 1 views
0

내 최근 프로젝트는 MySQL 데이터베이스에서 데이터를 쿼리하는 데 powershell을 사용해야하며 좋은 스크립트를 찾는다. 유일한 문제는 스크립트가 항상 int 값 (정확히 반환 항목의 수)을 출력한다는 것이다. . 이 출력을 피하는 방법? 내가 얻고 싶은 것은 쿼리 데이터뿐입니다. 다음은 스크립트입니다PowerShell 스크립트를 사용하여 데이터베이스를 쿼리 할 때 int 값 출력을 피하는 방법은 무엇입니까?

$mysqlDllFilePath = "C:\temp\powerShellScript\MySQL.Data.dll" 
[void][system.reflection.Assembly]::LoadFrom($mysqlDllFilePath) 

$myconnection = New-Object MySql.Data.MySqlClient.MySqlConnection 

$myconnection.ConnectionString = "server=localhost;userid=root;password=admin;database=temp;pooling=false" 

$myconnection.Open() 

$mycommand = New-Object MySql.Data.MySqlClient.MySqlCommand 

$mycommand.Connection = $myconnection 

$mycommand.CommandText = "SELECT SiteGuid,SiteName,ProductEdition,ProductVersion from site" 

$adapter = new-object MySql.Data.MySqlClient.MySqlDataAdapter 

$adapter.SelectCommand = $mycommand 

$ds = new-object System.Data.DataSet 

$adapter.Fill($ds) 

$myconnection.close() 
$ds.Tables[0] 

그리고 스크립트의 출력 :

PS C:\Users\jason> C:\temp\powerShellScript\Get-ConfigSite.ps1 
2 

SiteGuid     SiteName     ProductEdition   ProductVersion 
--------     --------     --------------   -------------- 
123f7267-757c-4864-b0... simulatedSite   PLT      7.1 
526f7267-757c-4864-b0... simulatedSite   PLT      7.1 

어떻게 출력 값 "2"를 방지하기 위해?

+0

가능한 복제본 [PowerShell의 출력을 무시하는 더 나은 (클리너) 방법] (http://stackoverflow.com/questions/5260125/whats-the-better-cleaner-way-to-ignore-output-in) -powershell) – Matt

답변

0

"$ adapter.Fill ($ ds)"문 출력의 이유를 알았습니다.이 값을 보유 할 변수를 선언하면 콘솔에 출력되지 않습니다. 어쩌면 그것은 powershell의 문법 일 것입니다. 해결 방법은 해당 진술을 "$ count = $ adapter.Fill ($ ds)"로 변경하는 것입니다. 어쨌든, 고마워.

+0

더미 변수를 선언하고 싶지 않다면 식을'[void]'로 변환하십시오. '[void] $ adapter.Fill ($ ds)' –

관련 문제