简体   繁体   中英

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. 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." 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. There is no connection between these two worlds.

I would love to then have this new database populate a very basic .net page. In a nutshell, run powershell script, transfer that data to my database, database is attached to a .net web page.

在此处输入图片说明

Currently in Table:

在此处输入图片说明

Powershell Script:

$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:

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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