0
我已經掌握了使用PowerShell執行以下SQL腳本。將輸出存儲在CSV文件中
cls
foreach ($svr in get-content "demo.txt")
{
$con = "server=MC1-PQ10X.RF.LILLY.COM\SQL01;database=mylilly_WSS_Content_INCTSK0014840;Integrated Security=sspi"
$cmd = "SELECT
Docs.DirName + '/' + Docs.LeafName AS 'Item Name',
DocVersions.UIVersion,
(DocVersions.UIVersion/512) as Version_Label, DocVersions.Level, DocVersions.TimeCreated
FROM DocVersions FULL OUTER JOIN Docs ON Docs.Id = DocVersions.Id
-- INNER JOIN Webs On Docs.WebId = Webs.Id
--INNER JOIN Sites ON Webs.SiteId = SItes.Id
WHERE (DirName LIKE '%globalcontentrepository%')
AND (IsCurrentVersion = '0')
AND (DocVersions.Id IN ('$svr'))"
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $con)
$dt = new-object System.Data.DataTable
$da.fill($dt) |out-null
$dt | Export-Csv music.csv -Encoding ascii -NoTypeInformation
}
我正在面對上述代碼的問題是關於輸出。對於每個$svr
此代碼正在創建一個新的CSV文件。輸入文件包含大約1000個輸入。我的要求是所有的輸出應該存儲在同一個文件中,而不是創建新文件。
我根本不知道powershell等,但文檔講述了一個'-Append'參數:http://technet.microsoft.com/en-us/library/hh849932.aspx – PeterMmm