Re: Powershell to compare to Directory Trees?



Thanks, this is proving very helpful! and gives me a better idea of how
PowerShell Scripting works.

One question I CANNOT find the answer to:

In *INX one can hit <Ctrl+D> or <Ctrl+Z> to suspend a process usually as a
prelude to sending it to the background or killing the process. How do I do
this in PowerShell?



"Shay Levi" wrote:


Here's a sample Powershell script

$source="C:\Backup"
$destination="D:\temp\backup"

get-childitem -path $source -recurse | where {!$_.PSIsContainer} |
foreach {
$path=$destination+$_.fullname.remove(0,$source.length)

# test if the file already exist on destination direcotry
if(test-path $path -pathtype leaf){

# if the file sizes are not equal copy the file again - overwrite
if($_.length -ne (get-childitem $path).length){
write-host "files $($_.name) length dont match"
copy-item $_.fullname -destination $path
}
} else {
write-host "the file $($_.name) doesn't exist, copy to destination"
copy-item $_.fullname -destination $path -force
}

}


--
Shay Levi
------------------------------------------------------------------------
Shay Levi's Profile: http://forums.techarena.in/member.php?userid=35878
View this thread: http://forums.techarena.in/showthread.php?t=859035

http://forums.techarena.in


.