Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Need to get SQL InstanceName and Database name in a CSV file using powershell.

$
0
0

I need to get the instance names and database names in a SQL 2008R2 server into a CSV file using PowerShell for running my backup script.

Desired Format.

Instance,Database
Instance1,Database1
Instance1,Database2
Instance2,Database1
Instance2,Database2

I hope my requirement is clear.

I m currently using

import-modulesqlps


cd

SQLServer:\SQL\Localhost


$instances

=Get-childitem

foreach($instancein$instances)

{

  

$instancename=$instance.name

  

$path="sqlserver:\sql\$($instance.name)\databases"


 

get-childitem-Force-path$path|Select-ObjectName,$instancename|Export-csvj:\instance_4.csv-NoTypeInformation-append-force


  }


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>