Further restrict powershell results by drive path

Regarding the previous case (29109977 I am running into another issue. Originally this was completed on a system which only had one set of users in it but we are now looking to run it where individual users need to be further broken up. Attached are the Results.ps1 and SendEmail.ps1 scripts which are in use. This statement specifically is what results in the information we require: Where-Object -Property ShareRelativePath -Match "S2K". However, we need to be able to specify an entire path of C:\Application\S2K1, S2K2, S2K3, etc. Right now it is giving me all of the D:\Application\S2K1, S2K2, etc and other drives. However, I only want to receive one drives information. Please let me know if any further clarification is needed.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

-match expects a Regular Expression. You're not using any feature that a RegEx offers, so -match is overkill (and can lead to unexpected results if you're not aware that you're working with a RegEx).
Try to use -like and a standard wildcard:
Get-SmbOpenFile | Where-Object {($_.ShareRelativePath -like "C:\Application\S2K1*") -and ($_.ShareRelativePath -notlike "*IMAGES*")} | Sort-Object ClientUsername | Select-Object -ExpandProperty ClientUsername

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mase2kAuthor Commented:
Interesting. That could explain some weird results we get from time to time. I modified the way you recommended and got the following. Any thoughts?

WARNING: Memory usage of a cmdlet has exceeded a warning level. To avoid this situation, try one of the following: 1)
Lower the rate at which CIM operations produce data (for example, by passing a low value to the ThrottleLimit
parameter), 2) Increase the rate at which data is consumed by downstream cmdlets, or 3) Use the Invoke-Command cmdlet
to run the whole pipeline on the server. The cmdlet that exceeded a warning level of memory usage was started by the
following command line: Get-SmbOpenFile | Where-Object {($_.ShareRelativePath -like "C:\Application\S2K*") -and
($_.ShareRelativePath -notlike "*IMAGES*")} | Sort-Object ClientUsername | Select-Object -ExpandProperty ClientUsername
Mase2kAuthor Commented:
I was able to implement your instructions successfully. I no longer required the -and for images since I was keying in on a folder specifically. Also I needed to specify Path instead of ShareRelativePath in order to see the whole path. This is working well for me now:

Get-SmbOpenFile | Where-Object {($_.Path -like "C:\Application\S2K*")} | Sort-Object ClientUsername | Select-Object -ExpandProperty ClientUsername
Mase2kAuthor Commented:
I really appreciate your assistance on this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.