Share via


How To Use Select-String NotMatch Parameter?

Question

Sunday, January 24, 2016 6:07 AM

Hi

The following powershell command correctly returns a list of PackageFullNames, of installed apps. 

Get-AppxPackage | out-string -stream |sls PackageFullName

The following is intended to return the simple name, and exlude PackageFullNames. But it fails:

Get-AppxPackage | out-string -stream |sls Name -notmatch "PackageFullName"

The error is  with "sls : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input."

How to make this work?

Thx  

All replies (3)

Sunday, January 24, 2016 7:43 AM ✅Answered

I dont quite understand what you want to do here? What is the simple name?

Is this what you want?

Get-AppxPackage | select Name


Sunday, January 24, 2016 12:49 PM ✅Answered

Well I agree with EckiS that the Select-Object command would be the way to go.

Looking at the Select-String documentation "-NotMatch Finds text that does not match the specified pattern.", so it does not accept another pattern, but returns what does not match the pattern at position 1.

So

Get-AppxPackage | out-string -stream |sls Name -notmatch

Returns all the lines that do not contain name (opposite to what you want).

The pattern in Select-String is a regular expression so that allows much control but adds complexity. I know enough about regular expressions to know I know nothing about regular expressions. but...

Get-AppxPackage | out-string -stream |sls ^Name

Returns just the lines that begin with name, the ^ Anchors the match string to the beginning of a line.


Sunday, January 24, 2016 4:18 PM

ah, ok. i misunderstood notmatch. As you correctly surmised, i'm trying to get lines that contain name, but not ProjectFullName. I guess sls can't do that? Thx for the anchor tip!