I have been trying to find a way to set my current working directory to a parent folder of a file so that I can copy a PDF that lives in a folder above a particular folder.
Basically what I am trying to do is this; Check which folders on a share have been modified in the last day Recursively search through those modified folders for a clxml file that contains a word I need Set my current location to that path, browse back a folder and copy out any PDF's to a new location.
So far I have everything working except I can't figure out how to set my current directory to the location of the clxml within the foreach loop. I can't figure out what needs to go between the final Get-ChildItem and my copy-item
$ClxmlFolder = Get-ChildItem "\\clwsdrapsi02\BATCH STORAGE\" -Directory| Where-Object {$_.LastWriteTime -ge ((Get-Date).Date) -and $_.LastWriteTime -lt ((Get-Date).Date).AddDays(+1)}
$ClxmlPath = Get-ChildItem $ClxmlFolder.FullName -Recurse -Directory -Include 'clxml' | Select-Object -Property FullName, Directory
foreach ($Folder in $ClxmlPath)
{
$ClxmlPath.FullName
break
}
foreach ($File in $ClxmlPath)
{
$ClxmlFile = Get-ChildItem $ClxmlPath.FullName -Recurse -Filter "*.clxml" | Where-Object {Select-String Newton $_ -Quiet} | Select-Object -Property Fullname, Directory
$ClxmlFile.Fullname
Copy-Item .\*.PDF -destination "C:\test uploads\Uploaded" -Recurse -Force
Break
}