0

forum.... still wkg on my POS skills. using dbatools.. I'm trying to run some informational queries, against multiple SQL instances. Is there a way to derive/use the server name from CMS to initialize the $server variable? How could I accomplish. I'm using:

Get-DbaRegisteredServer -SqlInstance CMSServer

There is a -ServerName parameter that contains the server name. How could I use it to do this, against each server (or any better way I'm open for)

Import-Module dbatools
$servers = "localhost\instance1" # this would be all the Live servers
get-dbadatabase -SqlInstance $servers -ExcludeDatabase master, model, msdb, tempdb | Select SqlInstance, Name, RecoveryModel, Compatibility, Owner, PageVerify, TargetRecoveryTime, IsReadCommittedSnapshotOn, SnapshotIsolationState, @{l="QueryStoreState";e={$_.QueryStoreOptions.ActualState}} | Export-Csv -Path c:\bin\databasestatus.csv

Thanks in advance!!

SQLSeeker
  • 1
  • 1

1 Answers1

1

The output of Get-DbaRegisteredServer is suitable for passing directly into Get-DbaDatabase (which accepts a collection of SQL Server instances).

$servers = Get-DbaRegisteredServer -sqlinstance CMSServer;
Get-DbaDatabase -SqlInstance $servers -excludesystem | Select-object SqlInstance, Name, RecoveryModel, Compatibility, Owner, PageVerify, TargetRecoveryTime, IsReadCommittedSnapshotOn, SnapshotIsolationState, @{l="QueryStoreState";e={$_.QueryStoreOptions.ActualState}} | Export-Csv -notypeinfo -Path c:\bin\databasestatus.csv
alroc
  • 27,574
  • 6
  • 51
  • 97