Powershell Filter on multiple columns that are not null from list object

Chilly 116 Reputation points
2021-02-24T00:31:09.45+00:00

Ok folks I am trying to figure out how to filter multiple columns for content that is not null. The full story is: The goal is to find all the workflows that are failing. From looking at the workflow status page there are hundreds. I do not have server access and I am not JavaScript savvy. My best tool for most jobs is Powershell. Using Invoke-restmethod I retrive list items from a SharePoint list and I need to filter on workflow status. The workflow status columns could be anywhere between 1 - 10 columns. I am able to identify the columns by selecting fields with the property TypeAsString -eq "WorkflowStatus". But I was unable to figure out how to filter on any of the columns that are not null.

There is more to figure out, but at the moment I am just trying to filter dynamically.

Any ideas?

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Chilly 116 Reputation points
    2021-02-24T16:27:55.147+00:00

    Ok, this is insane have you seen the filter function? I just discovered it! (for myself of course).

    I happen to be playing around with functions to filter my content and saw that the filter word I used was not acting like other functions. Then that got me to googling to find this page: https://4sysops.com/archives/the-powershell-filter-2/

    I did not know that this was a thing, who would have thought? Awesome!

    so following the example here is what I came up with for my situation:

     filter myfilter {
    
      foreach ($wf in $workflowfields)
           {
            if ($_.$wf -ne $null)
                {
                  $_
                }
            }
    }
    
    $listitems | myfilter
    

    Whaaaaaa laaaa stuff is filtered where the workflow status fields are not null!!!!
    This gives me the whole item object too!

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2021-02-24T06:02:56.503+00:00

    Hi,

    Does this work for you?

    $properties = ($item.PSObject.Properties | Where-Object{$_.Value}).name  
    $item | Select-Object -Property $properties  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Chilly 116 Reputation points
    2021-02-24T15:14:52.72+00:00

    Close. that is very close. That is exactly what I have started with. But I need it to include the whole item, But only items that are not null in the specific properties.
    Here is the line break down of what I need.

    This is perfect. I started tis way to get all the column names I wanted.
    $properties = ($item.PSObject.Properties | Where-Object{$_.Value}).name

    So this will only select the properties, not the whole item.
    $item | Select-Object -Property $properties

    What I am trying to accomplish is this:
    $items | ? {$_.$properties -ne $null}

    Does this make sense?

    Thank you so much for taking time out to help!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.