I want a simple way to exclude the system folder from the searches in PowerShell.
I use the following script:
$mysys = 'c:\windows' PS C:\> Get-ChildItem -path . -Include *.txt -Exclude '$mysys' -Recurse
I basically want anything under c:\windows to be completely ignored, however, when I run the search, i continuously get errors as it searches under c:\windows; and in some cases also gives out results that it found.
Error: (why is it even going under c:\windows when I excluded it)
Get-ChildItem : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied. At line:1
char:1 + Get-ChildItem -path . -Include *.txt -Exclude '$mysys' -Recurse -Dept ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], UnauthorizedAccessExcept ion + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
For example, it includes: (this should all be excluded) (basically anything under c:\windows)
> > Directory: C:\Windows\WinSxS\amd64_microsoft-windows-c..iser-inboxdatafiles_31bf3856ad364e35_10.0.14393.0_none_9eeac2cef7a25999 > > > Mode LastWriteTime Length Name > > ---- ------------- ------ ---- > -a---- 7/16/2016 6:42 AM 855814 hwcompat_RS1.txt > ------ 7/16/2016 6:42 AM 1764 hwexclude_RS1.txt > ------ 7/16/2016 6:42 AM 1327 wucompat.txt
I basically want to do a recursive search under c:\ and then exclude whatever I don't want. Starting with c:\windows and everything under it.