Further restrict powershell results by drive path

Mase2k
Mase2k used Ask the Experts™
on
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.
Results.ps1
SendEmail.ps1
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
-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

Author

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

Author

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

Author

Commented:
I really appreciate your assistance on this.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial