何かがディレクトリ「A」にコピーされたときに追跡するスクリプトを作成し、それをファイルをプライベートネットワークに移動するために使用されるフォルダーにコピーしようとしています。そのディレクトリを「b」と呼びます。もう一方の端には、これらのファイルを「b」で取得し、それをパブリックネットワーク上の他のフォルダーをミラーリングするフォルダー「c」フォルダーにコピーするスクリプトがあります。最近フォルダー「a」にコピーされたファイルのみを取得したい。問題は、コピーの日付を追跡するプロパティがファイルにないことです。そこで、テキスト ファイルを使用して追跡することにしました。以下にこのスクリプトを書きましたが、うまくいきません。テキストファイルから情報を抽出すると、それはもはやオブジェクトではないからだと思いますか?とにかく、あなたが与えることができるどんな助けも大歓迎です。
$binaries = "\\network\home\binaries"
$owt = "\\server1\owt\binaries"
function Get-Directories ($path)
{
$PathLength = $path.length
Get-ChildItem $path -Recurse | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.substring($PathLength+1)
$_
}
}
$A= [IO.File]::ReadAllText("\\network\home\binaries\log\log.txt")
$B= Get-Directories $binaries
#$stream = [System.IO.StreamWriter] "\\network\home\binaries\log\log.txt" | % {$stream.WriteLine($b)}
#$stream.close()
Compare-Object $A $B -Property RelativePath, Name, Length |
Sort RelativePath, Name, Length -desc | % {
if ($file -ne $_.RelativePath) { $_ } } |
Where-Object {$_.SideIndicator -eq "=>"} |
ForEach-Object {
$file = $_.RelativePath
Echo F | xcopy "$binaries\$file" "$owt\$file" /S
}
$c= Get-Directories $binaries | % { $c >> "\\network\home\binaries\log\log.txt"}