![](/img/trans.png)
[英]Microsoft SQL Server-specific Parser and Script Generator for Visual Studio > 2010?
[英]SQL Server Studio + PowerShell Script/Output
當前,我有一個腳本,該腳本輸出一個.csv文件,該文件要填充我創建的新數據庫。 我從未使用過SQL Server Management Studio,但是我去了遠程服務器,右鍵單擊“數據庫”,然后單擊“新建數據庫”。 進入我稱為“ Hal0Results”的新數據庫,打開“表”,然后創建一個新表“結果”,但我現在不知道該怎么辦。 這兩個世界之間沒有聯系。
然后,我希望這個新數據庫填充一個非常基本的.net頁面。 簡而言之,運行powershell腳本,將該數據傳輸到我的數據庫,數據庫附加到.net網頁。
當前在表中:
Powershell腳本:
$serversList =
'svr01.xxx.com',
'svr03.xxx.com',
'svr05.xxx.com',
'svr06.xxx.com',
'Svr08.xxx.com'
#End of Server List
$serversList | ForEach-Object {
$os = Get-WmiObject -Class Win32_OperatingSystem -Computer $_
$disks = Get-WmiObject -Class Win32_LogicalDisk -Computer $_ |
Where-Object {$_.DriveType -eq 3} |
ForEach-Object {
'{0} {1:D} MB Free/{2:D} MB Used' -f $_.DeviceID,
[int]($_.FreeSpace/1MB), [int]($_.Size/1MB)
}
New-Object -Type PSCustomObject -Property @{
'FQDN' = $_
'ServerName' = $os.PSComputerName
'OperatingSystem' = $os.Caption
'Disks' = $disks -join ' | '
}
} | Export-Csv 'C:\output.csv' -Delimiter ',' -NoType
.csv文件中的結果:
ServerName FQDN Disks OperatingSystem
SVR01 Svr01.xxx.com C: 18019 MB Free/51097 MB Used | E: 22364 MB Free/25597 MB Used Microsoft Windows Server 2008 R2 Enterprise
SVR03 svr03.xxx.com C: 18320 MB Free/61337 MB Used | E: 50079 MB Free/56317 MB Used Microsoft Windows Server 2008 R2 Enterprise
SVR05 svr05.xxx.com C: 8862 MB Free/40857 MB Used | E: 5045 MB Free/10237 MB Used Microsoft Windows Server 2008 R2 Enterprise
SVR06 svr06.xxx.com C: 14253 MB Free/61337 MB Used | E: 35029 MB Free/56317 MB Used Microsoft Windows Server 2008 R2 Enterprise
SVR08 Svr08.xxx.com C: 6483 MB Free/40857 MB Used | E: 5921 MB Free/10237 MB Used Microsoft Windows Server 2008 R2 Enterprise
好吧,如果您只是想手動執行此操作,則可以使用csv導入:右鍵單擊數據庫->任務->導入數據,然后通過向導選擇csv文件。 這將創建數據庫並為您處理所有列名稱和數據類型。
如果您需要以編程方式進行此操作,則可以找到很多指南: 這是一個指南,還有很多其他指南
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.