Created
April 12, 2021 09:22
-
-
Save sotolf2/3122f0b766d0c313066a19417cbf2c8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# IP-Adressen woher wir verteilen will hier konfigurieren | |
$standorte = @{ | |
"XXXXXX" = New-Object -TypeName PSObject -Property ( | |
@{ Ip = "xxx.xxx.xxx.xxx" | |
Benutzer = "xxxx\admin" | |
Kennwort = ConvertTo-SecureString -String "xxxxxx" -AsPlainText -Force | |
}) | |
} | |
# Ordner wo die Dateen die wir verteilen wollen drinnen sind | |
$fileSourcePath = "\\xxx.xxx.xxx.xxx\Path\To\Files\" | |
try { | |
New-PSDrive -name "source" -PSProvider FileSystem -Root $fileSourcePath | |
} catch { | |
Write-Host "Konnte verbindung zu xxxx-nicht aufbauen" | |
cmd /c pause | out-null | |
$host.Exit() | |
} | |
# Der pfad nach \\xxx.xxx.xxx wo es herkopiert wird | |
$files = Get-ChildItem -Path "source:\" | |
foreach ($standort in $standorte.GetEnumerator()) { | |
Write-Host "Kopiert dateien an $($standort.Value.Ip) ($($standort.Name)):" | |
try{ | |
# Credentials Erstellen | |
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $standort.Value.Benutzer, $standort.Value.Kennwort | |
$to = "\\$($standort.Value.Ip)\xxxx$" | |
Write-Host $to | |
# Vorübergehenden drive mappen | |
New-PSDrive -name "dest" -PSProvider FileSystem -Root $to -Credential $cred | |
} catch { | |
Write-Host "--! Konnte nicht Verbindung aufbauen zu $($ipAddress.Name) !--" | |
continue; | |
} | |
try { | |
foreach ($file in $files) { | |
# von wo bis wo aufsetzen | |
$from = $fileSourcePath + $file | |
$to = "\\$($standort.Value.Ip)\_xxxx$\" | |
Write-Host " |-> $from -> $to" | |
# die Datei(en) kopieren | |
Start-BitsTransfer -Source ("source:\" + $file) -Destination ("dest:\" + $file) | |
} | |
} catch { | |
Write-Host "--! Konnte datei nicht übertragen $($ipAddresse.Name) !--" | |
continue; | |
} | |
try { | |
Remove-PSDrive -Name "dest" | |
} catch {} | |
} | |
Remove-PSDrive -Name "source" | |
Write-Host "Finished copying files" | |
cmd /c pause | out-null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment