I have this script that I need to basically get all the .pdf files in a folder and then in that moment it needs to check if any of those file names are in a txt file containing filenames and if it is it will do some set of steps, same as if it is not. I have only made it so far as im not very fluent with powershell.Below is what i got if anyone can help me out! Thanks!
$dir = "C:\Users\user\Downloads\*.pdf"
$names = "C:\Users\user\Downloads\content.txt"
#check for .pdf files in folder
If (Test-Path -Path $dir )
{
$files = Get-ChildItem $dir
foreach($file in $files)
{
# Steps to search for filename within $names file that contains list of files
# Steps if file found
{
#do these steps
}
else
{
#do these steps instead and then add all the filenames to $names file
Add-Content $names $file.Name
}
}
}
Else
{
Write-Host "N/A"
Exit
}