Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Script to retrieve Database name and creation date

$
0
0

Hi,

I have written the following script:

foreach ($Server in get-content "D:\Servers.txt")
    {
    #Retrieve Database list
    Invoke-Sqlcmd -query "select name ,create_date from sys.databases" -ServerInstance "$Server" |
    select-object @{label='ComputerName';expression={$Server}}, @{label='DatabaseName';expression={$_.name}}, @{label='Creation Date';expression={$_.create_date}}  | export-csv d:\test.csv
    }   

On screen it outputs correctly, as soon as I try and pipe it to a text file or try to output to CSV, it only exports one of the servers listed.

 

Any ideas ?

 

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles