First and foremost, a statement Get-ChildItem -Include *.dll
will return only file objects (unless you have a folder named <something>.dll
, which would be rather uncommon), so if you filter the output for directory objects ($_.PSIsContainer
) you will obviously come up with an empty result. Since the rest of your code suggests that you want files anyway just remove the $_.PSIsContainer
clause from your filter.
Also, the -Exclude
parameter applies to the name of the items. You can't use it to exclude (partial) paths. If you want files from the given directories omitted from the result you should exclude them in your Where-Object
filter with a regular expression match like this:
$_.FullName -notmatch '^C:\\windows\\(system|temp|winsxs)\\'
And finally, wildcard matches (-like
, -notlike
) require a *
wildcard at beginning and/or end of the expression if you want to match a partial string:
PS> 'abcde' -like 'a*e'
True
PS> 'abcde' -like 'c*e'
False
PS> 'abcde' -like '*c*e'
True
Without the leading/trailing *
the expression is automatically anchored at beginning/end of the string.
However, your pattern doesn't look like a wildcard expression in the first place. It looks more like a regular expression to me (to match paths containing \obj\
or ending with \obj
). For that you'd also use the -notmatch
operator:
$_.FullName -notmatch '\\obj\\'
From a perfomance perspective wildcard matches are more efficient, though, so it'd be better to use an expression like this:
$_.FullName -notlike '*\obj\*'
Making the trailing backslash optional is pointless, because Get-ChildItem
returns a list of *.dll files, so none of the full paths will end with \obj
.
Something like this should do what you want, assuming that I interpreted your code correctly:
$final = Get-ChildItem 'C:\' -Include '*.dll' -Recurse | Where-Object {
$_.FullName -notmatch '^C:\\windows\\(system|temp|winsxs)\\' -and
$_.FullName -notlike '*\obj\*' -and
$_.VersionInfo.LegalCopyright.Contains('Microsoft')
}