Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

How to use -Include and -Exclude as Input Parameter

$
0
0

Hello

I am generating a CSV of list of files and folders for selected path. I created following script and it is working correctly.

$Eliminate = @("*.docx","*.xlsx")
$Include = @("*.pptx","*.txt")
$AllFiles = @()
foreach ($file in get-childitem $FolderPath  -recurse -Exclude $Eliminate -Include $Include| Select-Object FullName, Root, Directory, Parent, Name, Extension, PSIsContainer, IsReadOnly, Length, CreationTime, LastAccessTime, LastWriteTime, Attributes)
{
...
}
$AllFiles |Export-Csv $report –NoTypeInformation

Now I have following questions

How can I pass as input parameter for Include and Exclude?

Secondly When I am using Include, it is working correctly but it is skipping the folder of Include variable values.

Please advise how can I achieve this?


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>