0

I am using the PnP SharePoint powershell moudle and trying to filter a users list based on a variable.

Currently here is what I have:

$RootFolder = '/Path/To/Folder'

$folders = Get-PnPFolderItem -FolderSiteRelativeUrl $RootFolder

foreach ($folder in $folders){
    $user = Get-PnPUser | Where Title -Like "*$folder.Name*"}
}

This does not return results. However, if i change | Where Title -Like "*username*" it works fine.

The user name format is "FirstName LastName (FLastName)" and i am trying to filter based on "FLastName".

I tried single quotes and also created a variable $username = "*" +$folder.Name+ "*" and used that variable instead but no difference.

Any thoughts would be appreciated.

2 Answers 2

2

Try this:

Where Title -Like "*$( $folder.Name )*" 

The variable expansion/replacement ends with the "." in a simple string.

0
0

Edited to use Mike Smith's solution.

I was able to get this to work by doing the following adjustment (adding string to the variable)

$RootFolder = '/Path/To/Folder'

$folders = Get-PnPFolderItem -FolderSiteRelativeUrl $RootFolder

foreach ($folder in $folders){
    $user = Get-PnPUser | Where Title -Like "*$($folder.Name)*"}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.