none
Powershell dbatools combining result of multiple Get-dbaxxx commands to generate a report RRS feed

  • Question

  • I'm new to powershell and dbatools. It is a great tool but when I try to combine the result of few different commands into an array to be exported to csv, it is not providing the intended result. It is only printing the output of first commands. Can someone please help me with joining the result of all three variables? What I'm trying to do is writing a script to automate generating our SQL Server Inventory and Capacity assessment report. 

    Here's my code so far:
    $Servers = Get-Content 'C:\Users\temp\ServerList.txt'
    
    $reportData = @()
    
    foreach ($Server in $Servers) {
    
      if (Test-Connection -ComputerName $Server -Count 1 -ErrorAction 'SilentlyContinue') {
    
        $OSInfo=Get-DbaOperatingSystem -ComputerName MyServer| Select ComputerName, OSVersion, Version, Architecture
        $DiskSPace=Get-DbaDiskSpace -ComputerName MyServer| Select ComputerName, Label, Name, Capacity, Free
        $SQLInstanceInfo=Connect-DbaInstance -SqlInstance MyServer | Select DbaInstanceName, Edition, NetPort, IsClustered, Processors, ProductLevel, ServiceName, 
    
    
        $reportData +=$OSInfo
        $reportData +=$DiskSPace
        $reportData +=$SQLInstanceInfo
    
      }
    
      else {
    
        write-host $Server "not connected"
      }
    }
    
    Write-Output $reportData | Format-Table


    Friday, March 13, 2020 9:00 PM

All replies