【问题标题】:SQL Server Studio + PowerShell Script/OutputSQL Server Studio + PowerShell 脚本/输出
【发布时间】:2015-09-01 08:00:36
【问题描述】:

目前,我有一个输出 .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 

【问题讨论】:

    标签: .net sql-server powershell csv database-connection


    【解决方案1】:

    如果您只是想手动执行此操作,您可以使用 csv 导入:右键单击您的数据库 -> 任务 -> 导入数据并通过向导并选择您的 csv 文件。这将为您创建数据库并处理所有列名和数据类型。

    如果您需要以编程方式执行此操作,这里有很多指南:here is a guide there are many others

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多