简体   繁体   English

SQL Server Studio + PowerShell脚本/输出

[英]SQL Server Studio + PowerShell Script/Output

Currently, I have a script that outputs a .csv file that I would like to populate a new database I created. 当前,我有一个脚本,该脚本输出一个.csv文件,该文件要填充我创建的新数据库。 I have never used SQL Server Management Studio, but what I did I went to my remote server, right-clicked on "Databases" clicked "New Database." 我从未使用过SQL Server Management Studio,但是我去了远程服务器,右键单击“数据库”,然后单击“新建数据库”。 Went into that new database that I called, "Hal0Results" opened "Tables" then created a new table, "Results" But I do not know what to do now. 进入我称为“ Hal0Results”的新数据库,打开“表”,然后创建一个新表“结果”,但我现在不知道该怎么办。 There is no connection between these two worlds. 这两个世界之间没有联系。

I would love to then have this new database populate a very basic .net page. 然后,我希望这个新数据库填充一个非常基本的.net页面。 In a nutshell, run powershell script, transfer that data to my database, database is attached to a .net web page. 简而言之,运行powershell脚本,将该数据传输到我的数据库,数据库附加到.net网页。

在此处输入图片说明

Currently in Table: 当前在表中:

在此处输入图片说明

Powershell Script: 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

Results in .csv file: .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 

well if you are just looking to do this manually you can use the csv import: right click your database -> tasks -> Import data and go through the wizard and select your csv file. 好吧,如果您只是想手动执行此操作,则可以使用csv导入:右键单击数据库->任务->导入数据,然后通过向导选择csv文件。 That will create the database and handle all the column names and data types for you. 这将创建数据库并为您处理所有列名称和数据类型。

If you need to do this programmatically there are plenty of guides out there: here is a guide there are many others 如果您需要以编程方式进行此操作,则可以找到很多指南: 这是一个指南,还有很多其他指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM