Powershell Automation remove instance from monitoring

Hello,

I am trying to prepare a script to automate instance management to add and remove servers to SQLDM monitoring. I was able to add instance to SQLDB with "New-SQLdmMonitoredInstance", but the issue is with remove instance from SQLDM.I couldn't able to remove instances from SQLDB, getting following error,

Remove-SQLdmMonitoredInstance : Cannot find path 'dm:\Instances\10000-TEWADYX' because it does not exist.

The command I am using to remove instance is, 

          Remove-SQLdmMonitoredInstance -Path \Instances\10000-TEWADYX

Some help would be greatly appreciated.

  • Below is a screenshot example of me using the command. Notice that there is an error generated in my example as well. The error is because the SQLdmRepository database is case-sensitive and the names didn't match. Once I corrected the casing to match what's in the repository database, then the command worked as expected. 

    I know that the cmdlet has an option to use the -Path parameter to specify the name of the monitored instance. However, PATH doesn't work with named instances. As such, I typically always use the Escape-SQLdm method since it works with both named instances and default instances. 


    I hope that helps.

  • Tep,

    Thank you for your prompt response. I tried with Escape-SQLdm and still getting same error. In this case I don't have named instances and I using same case that I see on dashborad. BUt some reason I don't see this instance under "MonitoredSQLServers" DB table. I am new to Idera, and I am not sure how DB supposed to register it in DB

    PS dm:\> Remove-SQLdmMonitoredInstance -Path (Escape-SQLdmName -Name 10000-TEWADY)
    Remove-SQLdmMonitoredInstance : Cannot find path 'dm:\Instances\10000-TEWADY' because it does not exist.
    At line:1 char:1

  • Try removing the "-Path" from the line. Notice that in my example, it doesn't include -PATH.

    Remove-SQLdmMonitoredInstance (Escape-SQLdmName -Name 10000-TEWADY)

    However, if you don't see it in the MonitoredSQLServers table, I'm not sure you'll be able to do that. Can you share screenshot of your dashboard showing the instance name?

  • even without "-Path", command returning same error.

    Sorry, I couldn't provide our real instance name and the screenshot. The instance name provided above was not real as well. However I made sure that the correct instance is added to dashboard  and it is not available in DB table. I added this new instance to SQLDM couple of hours back, is ther eany grace period to register in DB?

    Following are the command I used to add a instance to SQLDM,

    add-pssnapin sqldmsnapin
    New-SQLdmDrive dm <IDERAServer> SQLdmRepository
    cd dm
    New-SQLdmMonitoredInstance -Path 10000-TEWADY -WindowsAuthentication -tags UATInstances

  • Then the only thing that I can think of at this point would be that perhaps you need to enclose the server name? I'm wondering if maybe the - character is being misinterpreted. But if you don't see the server name in the MonitoredSQLServers table, that's going to be the bigger problem.

    The image above shows you the different places you can see the instance name. I've also included the Monitored SQL Servers Properties window (shown on the right side of the image) which shows you both the name registered in the tool as well as the friendly name (towards the middle of the properties windows).

    In the servers list (on the left side), you can also see the friendly name "ABC" and the registered instance name in parenthesis (KIBA\SQL2017). To use the cmdlet, you need the registered instance name and not the friendly name.

    SELECT InstanceName,FriendlyServerName FROM MonitoredSQLServers

    Unfortunately, without seeing what's registered, I'm not sure I can offer any other suggestions.