I am writing a simple DLL copying script to help my dev team in setting up their local environments. I check the build devdrop folder and get a list of DLL files. I then look at the local folder and copy any newer DLLs over.
My problem is when the local folder is empty (i.e. the first time the script runs) it all falls apart.
$newFiles = Get-ChildItem -recurse -path "$drop\$latest\ship" -name
$oldFiles = Get-ChildItem -recurse -path $bin -name
$files = Compare-Object $newFiles $oldFiles -IncludeEqual -PassThru
$files | Where-Object { $_.SideIndicator -eq '<=' -or $_.SideIndicator -eq '=='} | % {
Copy-Item -Path "$drop\$latest\ship\$_" -Destination $bin -Force
}
When $bin is empty the gci call leaves $oldFiles as null, giving me a nice error:
Compare-Object : Cannot bind argument to parameter 'DifferenceObject' because it is null.
I have searched around and all how-tos for Compare-Object don't seem to deal with this. I could check if the folder is empty and then copy all the files over, but I was wondering if there was a better way.
Cheers.