Forum Discussion
If that checks SiteUrl value exists in array using PnP
Hi, Thomas.
If we run with your assumption that the issue is with line 16, then -notin is probably not the appropriate operator. Try the following instead:
if ($ListItems.FieldValuesAsText.SiteUrl -notcontains $Site.Url) {
Some diagnostic information that would help is:
- The results from running:
$ListItems.FieldValuesAsText.SiteUrl.pstypenames;
- The results from running:
$ListItems.FieldValuesAsText.SiteUrl | Select-Object -First 5;
Basically, I'm looking for some type information and sample data given I don't work with SharePoint and cannot replicate your tests.
Cheers,
Lain
- LainRobertsonNov 21, 2023Silver Contributor
As a quick clarification after having gone and fact-checked myself on what I thought I remembered about -notin (where I thought it only behaved against collections), it turns out I recalled incorrectly as it works against arrays as well. This means the suggestion I made about -notcontains likely won't make any difference.
That said, the diagnostic commands are still useful since I have no idea what the types and example data look like.
Cheers,
Lain
- CardinalNightNov 21, 2023Brass Contributor
Hi, how would enter these type checks in the script? Can you provide please. When I run one of the provided lines, then run $listItems it just shows:
Id Title GUID
-- ----- ----
280 6185d296-1919-4179-g654-02ae6bcec4d9
281 1a4efa4f-9f82-4543-b2345-26f459ec0b45
etc....- LainRobertsonNov 21, 2023Silver Contributor
Just the first line from your script and then the following two lines added after it:
$ListItems = Get-PnPListItem -List $List; $ListItems.FieldValuesAsText.SiteUrl.pstypenames; $ListItems.FieldValuesAsText.SiteUrl | Select-Object -First 5;Cheers,
Lain