For the files with extensions (".ipt", ".iam", ".ipn", ".idw") there may be a pdf equivalent, where pdf file may have exact name or it may have characters added to it.
I want to exclude the files with extensions mentioned above and their pdf equivalent but if there are any other pdf files I want those. I also want rest of the files from the folder.
In the script I construct the pdf file which works. But I can't seem to filter it out.
Like Powershell refuses to acknowledge that this file exist. It excludes the file extension I dont want but wont exclude the pdf that was constructed.
The path looks like \\nml-fp\EngDesignLib\068\068179.001 where 068, and 068179.001 come from SQL db. Therefore, have to stick with the path that is being created.
In the script below I have tried most of the cmdlets used to filter out.
-and -not ($_.Name -contains $pdf.Name)
($_.Name -notcontains $pdf.Name)
($_.Name -notLike $pdf.Name)
-not ($_.Name -like $pdf.Name)
($_.Name -notIn $pdf.Name)
($_.Name -notIn $arrayIdwPdf )
If($testPathEngDesign){
Get-ChildItem -Path $PathEngDesign -File -Recurse -ErrorAction SilentlyContinue -Force
|ForEach-Object{
$file = $_
$extension = $_.Extension
$baseName = $file.Basename
$filename = $file.Name
if( $extension -in '.ipt', '.iam', '.ipn', '.idw') {
$filePdf = "*$($baseName)*.pdf"
$pdfFilePath = $file.FullName -replace ($file.Name, $filePdf)
$pdf = Get-ChildItem -Path $pdfFilePath
$fileNamePdf = $pdf.Name
$filePdfPath = $pdf.FullName
$arrayIdwPdf += $filenamePdf
$excludeList = @("*.ipt", "*.iam", "*.ipn", "*.idw",$pdf.Name)
Get-ChildItem -Path $PathEngDesign -Exclude $excludeList -File -Recurse | ForEach-Object
{if ($_.Name -notlike $pdf.Name ) {
$csvData = [PSCustomObject]@{
PartRn = [String]$partRn
DocumentNumber = [String]$PartNo
Revision = [String]$revision
Classification = [String]$classification
FileName = [String]$_.Name
Path = [String]$_.FullName
}
$csvDataArray += $csvData
$csvData | Export-Csv -Path $csvFilePath -Force -Append
From your narrative, it sounds to me that you want something like this: