1

嗨,我已经构建了一个运行良好的脚本,除了一件事,有时返回的字符串太长以至于它不适合 powershell 控制台,当我稍后将文本发送到 Richtextbox 时,我得到了所有...... . 最后而不是整个字符串

$username = "myaccount"
$sqlconnection = New-Object system.data.sqlclient.sqlconnection
$sqlconnection.ConnectionString ="server=myserver\sccm;database=sccm;trusted_connection=true;"
$sqlconnection.Open()
sqlcmd = New-Object system.data.sqlclient.sqlcommand
$sqlcmd = $sqlconnection.CreateCommand()
$sqlcmd.CommandText = "SELECT Info from SCCM.dbo.log WHERE Username = '$username'"
$sqlcmd.Connection = $sqlconnection
$data = New-Object system.data.sqlclient.sqldataadapter $sqlcmd
$dataset = New-Object system.data.dataset
$data.Fill($dataset)
$global:result = $dataset.Tables

我无法在任何地方指定 -Width 参数,所以我不知道如何获得结果的全长?

4

1 回答 1

0

您可以将数据集保存为 csv 文件,而不是在 powershell 中显示:

#Fill the dataset with the SQL response. Using [void] redirects console output to null (don't display)
[void]$data.Fill($dataset)

#Pipe the contents of the dataset. Use Select to select all columns/properties excluding those that were created by the DataSet object (not actual data)  

#Pipe to Export-CSV to create a CSV file, use -notypeinformation flag to skip Object type information from the file (e.g. System.String etc)  

$dataset.Tables[0] | Select *  -ExcludeProperty RowError, RowState, HasErrors, Table, ItemArray | Export-CSV -notypeinformation -path C:\Somedir\Somefile.csv
于 2013-08-14T19:09:27.630 回答