I'm very new to Powershell and I cannot figure out what i'm doing wrong with the Where-Object.
The following script executes perfectly fine (URL removed):
Connect-PnPOnline -Url [SomeURL] -UseWebLogin
Get-PnPListItem -List "workproretentiontest" | Select-Object @{label="Filename"; expression={$_.FieldValues.FileRef}}, {$_.FieldValues.FileLeafRef}
Showing these results:
I need to filter for individual results here but I cannot figure it out (and many hours have been lost!)
I feel like i've tried every combination possible of the following but can't figure out why it wont work
| Where-Object {$_.FieldValues.FileLeafRef -eq "201700007"}
What does work is this when I ask for nulls ( as in every record is returned when executing the following) which means the $_.FieldValues.FileLeafRef is always returning null?? But I cant work out why
| Where-Object {$_.FieldValues.FileLeafRef -eq $null}
Any help or guidance would be massively appreciated :)
CodePudding user response:
The why you wrote this, there will be literally a property called '$_.FieldValues.FileLeafRef'
on the object, so you would have to reference it as such:
| Where-Object {$_.'$_.FieldValues.FileLeafRef' -eq "201700007"}
But it would be better style, got give it a proper name in the first place, just as you did with "Filename"
:
Select-Object @{label="Filename"; expression={$_.FieldValues.FileRef}},
@{label="Date"; expression={$_.FieldValues.FileLeafRef}} |
Where-Object Date -gt "201700007"