• Thanks a lot Haword, I really appreciate your help. However I am getting syntax errors on it. Lets say my instance name is "myserver\dba" (where myserver is my machine name and dba is instance name for my CMS server . I have pasted the query exactly how I put it in the powershell script (with valide server and instance name) but getting error which is posted at the End of this script: Can you please assist me where I am doing things wrong? I don't need where clause for now.

    Thanks again for your help.

    $instanceNameList = invoke-Sqlcmd -query

    "SELECT [server_name] as Name FROM [msdb].[dbo].[sysmanagement_shared_registered_servers_internal] SSRSI join

    [msdb].[dbo].[sysmanagement_shared_server_groups_internal] SSSGI on SSRSI.server_group_id = SSSGI.server_group_id "

    -serverinstance "myserver\dba"

    $results = @() foreach($instanceName in $instanceNameList){$results += Invoke-Sqlcmd -Query

    "SELECT a.name, b.type, MAX(b.backup_finish_date)

    LastSuccessfulBackup,

    CAST((GETDATE() - MAX(b.backup_finish_date)) AS NUMERIC(5, 2)) IntervalInDays

    FROM master..sysdatabases a

    LEFT OUTER JOIN msdb..backupset b ON a.name = b.database_name

    where b.type='D'

    GROUP BY a.name, b.type

    ORDER BY a.name, b.type" -ServerInstance $instanceName.Name}$results| Where-Object {$_} | Export -Csv E:\Backup_log -NoTypeInformation

    Message

    Executed as user: myuser. A job step received an error at line 5 in a PowerShell script. The corresponding line is '-serverinstance "myserver\dba" '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Missing expression after unary operator '-'. '. Process Exit Code -1. The step failed.