I am comparing 2 arrays. 1 is a list of files and the other is a folder location. I am checking to see if a user has the files by checking for them by their name inside that folder. So if they have C:\folder\ and checking to see if file1.txt, file2.txt, file3.txt and file4.txt are there.
When testing it out on my computer I placed file2.txt and 4 in a different location to pretend that I did not have it. So when I ran my script it said that my Input Object was File2.txt and 4 (which is correct). I made a variable equal to the compare-object line. When I try to use the copy-item to tell it to go to a specific folder to grab that file it is missing, BUT I found out that Input Object is not compatable with copy-item.
*NOTE: The txt files contain nothing but random letters so they have something in them.
Is there any way I can use the compare-object to what I explained above to work with copy-item?
Here is what I have so far.
*If you comment out the copy-item line and run it, it will work. After that look at the variable $missingfiles and it will show you under the property "Input Object" that it shows the missing files.
$FileList = @("file1.txt", "file2.txt","file3.txt", "file4.txt") if ($UserFiles.Name -contains $_.Name) { $missingFiles = Compare-Object -ReferenceObject $FileList -DifferenceObject $Us
erFiles $missingfiles | foreach {copy-item $_.Fullname -Path "\\server\Folder" -Des
tination "c:\test\folder"}
} else { Write-Host "no files needed" }