trying to pass a list of servers to a parameter

Welcome Forums General PowerShell Q&A trying to pass a list of servers to a parameter

Viewing 2 reply threads
  • Author
    Posts
    • #194798
      Inactive
      Topics: 18
      Replies: 10
      Points: 0
      Rank: Member

      I am trying to use this powershell script to pull SQL Server information and place it in a table. It works great if I pass the server names in a comma delimited list. But I need it to work by pulling the list from the CMS(Central Management Server). The output from that query is a list of servers (1 per line). It works for other scripts but not this one.

      Here is the whole script but it is the last few lines I am having a problem with.

    • #194834
      js
      Participant
      Topics: 32
      Replies: 842
      Points: 2,687
      Helping Hand
      Rank: Community Hero

      I don’t know what get-sqldbinventory is. Unless its computername parameter accepts its value over the pipe byvalue, piping the names to it won’t work.

    • #194939
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero

      The function wrapper isn’t giving a really providing a lot of value here, you are just using it as a looping mechanism. You could be able to do something as simple as this:

      Your output is a data table and you don’t need to do any complex merges or anything that I can tell. If the temp table and destination table are the same schema, you should be able to pipe right to Write-SqlTableData. Here is a quick test:

      Output:

      You can also add -First to you CM Query to test if the process is working before running it on all servers:

      $allservers = Get-DbaCmsRegServer -SqlInstance localhost -Group CMS_SQLGROUP | Select-Object -Unique -ExpandProperty ServerName -First 3

Viewing 2 reply threads
  • The topic ‘trying to pass a list of servers to a parameter’ is closed to new replies.