Powershell connecting to multiple instances

  • I am new to Powershell and I am currently trying to figure out why the below is not returning the server\instance as part of the script. I am guessing its because of the named instance and the '\'

    It is returning the other info, just not the server\instance
    ---------------------------

    $instances = @('Server1\Instance1','Server1\instance2')

    $instances | ForEach-Object {get-childitem "SQLSERVER:\SQL\$_\databases" -Force} |
    Sort-Object size -descending |
    Select-Object @{n='Server';e={$_parent.Name}},name,lastbackupdate,size

    --------------------------------------

  • I believe it's because you're trying to apply a method to a property.  This should work


    $instances = @('Server1\Instance1','Server1\Instance2')

    $instances |
      ForEach-Object {Get-ChildItem "SQLSERVER:\SQL\$_\databases" -Force} |
      Sort-Object Size -Descending |
      Select-Object @{n='Server';e={$_.parent}}, name, lastbackupdate, size

  • much appreciated - that works!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply