我正在尝试使用PowerShell在我的数据库中打印一个人员表。我希望select statment以XML格式返回结果,并将其打印到屏幕上。 ATM我在打印到屏幕时遇到问题。
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=SQLSERVER;Database=myDatabase;user id=usr;password=pss;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = "SELECT TOP 100 * FROM people"
$cmd.connection = $conn
$reader = $cmd.ExecuteXmlReader()
write-output $reader
$conn.close()
$conn.ConnectionString = "Server=SQLSERVER;Database=myDatabase;user id=usr;password=pss;"
$conn.Open()
$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = "SELECT TOP 100 * FROM people"
$cmd.connection = $conn
$reader = $cmd.ExecuteXmlReader()
write-output $reader
$conn.close()