locked
Pipelining two cmdlets and need to select from both of them RRS feed

  • Question

  • I'm trying to write a script that returns the cluster name, the names of the resources in it, their IP and the state of the IP.

    This works except the State is blank because it's in get-clusterresource.

    I need the IP which is why I'm pipelining get-clusterparamter but when I do this I can't seem to return the State info.

    function Get-SQL-Clusters { param([string]$server) $servers = Get-Content -literalpath "C:\temp\sql_clusters.txt" if ($server -ne 1) { $files = ForEach ($box in $servers) {invoke-command -ComputerName $box {Get-ClusterResource | Get-ClusterParameter} | Where-Object {$_.Name -eq "Address"} | Format-Table PSComputerName, ClusterObject, State, Name, Value -AutoSize} } else {Write-Warning "'$server' is not a valid path."} return $files }


    Monday, February 5, 2018 10:00 PM

All replies

  • If you take time to learn how to format your code correctly then you might see what is happening.

    function Get-SQL-Clusters{
         param(
            [string]$server
        )
    
        $servers = Get-Content C:\temp\sql_clusters.txt       
        if ($server -ne 1){
            ForEach ($box in $servers) {
                invoke-command -ScriptBlock {Get-ClusterResource | Get-ClusterParameter} -ComputerName $box  |
                    Where-Object {$_.Name -eq 'Address'} |
                    Format-Table PSComputerName, ClusterObject, State, Name, Value -AutoSize
            }
        }else{
            Write-Warning "'$server' is not a valid path."
        }
    }
    

    "$server" seems to serve no purpose.

    "State" is not a property of a cluster parameter.

    Get-ClusterResource takes a cluster name to get the correct cluster.

    There is no need to use Invoke-Command to query clusters.  Use the cluster name to get the information.


    \_(ツ)_/

    • Proposed as answer by I.T Delinquent Tuesday, February 6, 2018 9:24 AM
    Monday, February 5, 2018 10:19 PM
  • That's my problem. IP is in get-clusterparameter, but I'm trying to write something where I get the cluster name, the resource names that have IP's, the IP of each of those resources and the state of the resource in one script and one result set.

    And I used invoke-command because I'm running these from a server with no cluster resource on it

    I'm thinking I might just have to use join-match.

    Tuesday, February 6, 2018 2:06 PM
  • Tuesday, February 6, 2018 3:26 PM
  • Here's an example of using -pipelinevariable to save (one instance of) the output of the first cmdlet to a variable and referring to it later:


    Get-CimInstance -ClassName Win32_Service -PipelineVariable service |
    Select @{Name="PID";Expression={$_.ProcessID}} |
    Get-Process |
    Select Name,CPU,@{Name='DisplayName';Expression={$service.DisplayName}}










    • Edited by JS2010 Tuesday, February 6, 2018 9:07 PM
    Tuesday, February 6, 2018 6:34 PM