expetrov
Goto Top

Kopieren des Verzeinisses A nach B (Daten überschreiben)

Hallo zusammen,

Auf ein Server muss ich ein Script erstellen, welches folgendes macht:

1. stoppen des Dienstes: "XY"
2. kopieren des Verzeichnisses D:\Source nach D:\Destination (Daten überschreiben)
3. kopieren des Verzeichnisses D:\Source nach \\filer\Destination (Daten überschreiben)
4. starten des Dienstes: "XY"
5. Verschicken eines Mails an User dass die Daten kopiert wurden.

Ich habe die untenstehende script erstellt, aber es wird nur ein Verzeichnisse kopiert.
Könnt Ihr bitte es kurz anschauen und mein script verbessern damit beiden Verzeichnisses kopirt wird.

Vielen Dank.

$ErrorActionPreference="continue"
#
$Source = "C:\Users\expetrov"
$Destination = "C:\Users\expetrov\Videos"
#
$Date = Get-Date -format M
$LogFile = "C:\temp\$Date-copy_log.txt"
#
$server = "localhost"
$running = Get-Service $service -ComputerName $server
$service = "Service"
#
if(Test-Path $LogFile){
Remove-Item $LogFile
#Write-Host "logfile wurde gelöscht" -ForegroundColor Red
sleep 10
}
#
if($running.Status -eq "Running"){
Stop-Service $service
#Write-Host service wurde erfolgreich gestopprt -ForegroundColor Green
sleep 20
}else {Write-Host Service könnte nicht gestoppt werden. }
#
Get-Date | Out-File $LogFile -Append
echo "SOURCE IS:$Source" | Out-File $LogFile -Append
Get-ChildItem $Source | Out-File "C:\temp\$Date-copy_log.txt" -Append
echo "COPY JOB STARTED" | Out-File $LogFile -Append
echo " " | Out-File $LogFile -Append

Get-ChildItem $Source -Recurse | ForEach-Object {
Try
{
$FilePath = $_.fullname
Copy-Item $FilePath -Destination $Destination -Recurse -force
$FilePath | Out-File $LogFile -Append
}
Catch
{
echo "error moving $FilePath" | Out-File $LogFile -Append
}
}
echo " " | Out-File $LogFile -Append
echo " " | Out-File $LogFile -Append
echo "COPY JOB FINISHED" | Out-File $LogFile -Append
echo " " | Out-File $LogFile -Append
echo "DESTINATION IS:$Destination" | Out-File $LogFile -Append
Get-Date | Out-File $LogFile -Append
##
if($running.Status -eq "Stopped")
{
Start-Service $service
#Write-Host service wurde erfolgreich gestartet

##
#Mailversand mit anhang

Content-Key: 297901

Url: https://administrator.de/contentid/297901

Printed on: April 19, 2024 at 23:04 o'clock

Mitglied: 126919
126919 Mar 02, 2016 updated at 08:45:15 (UTC)
Goto Top
Zum überschreiben einer ganzen Struktur nimm einfach robocopy in dein Skript mit rein
robocopy $source $destination /E
fk