I have a script (pasted below) that's supposed to do the following:
- Loops and grabs all files that match a defined pattern
- Copies those files into another location
- Move the original source file into another location (if copy was successful)
It's doing step #1 and #2 but step #3, Move-Item is not moving any files and I don't know why and I get no indication of an error
Can someone help? Thanks
$source = "C:\Users\Tom\"
$source_move = "C:\Users\Tom\OldLogBackup1\"
$destination ="C:\Users\Tom\Mirror\"
if(-not(Test-Path $destination)){mkdir $destination | out-null}
#Step 1
ForEach ($sourcefile In $(Get-ChildItem $source | Where-Object { $_.Name -match "Daily_Reviews\[\d\d\d\d-\d\d\d\d\].journal" }))
{
#escape filename because there are brackets in the name!
$src = [Management.Automation.WildcardPattern]::Escape($sourcefile)
#Step 2
Copy-Item $src $destination
### Check for a successful file copy
if($?)
{
if(-not(Test-Path $source_move)){
echo "Path does not exist!"
} else {
echo "Path exists!"
### Step 3
### Move original source file someplace else
Move-Item $source_move$sourcefile $source_move
if($?)
{
echo "Source file successfully moved"
} else {
echo "Source file was not successfully moved"
}
}
}