Created
August 16, 2017 15:41
-
-
Save RobinBeismann/813e68f6d11f2daaaa1f14c3e8f4e3b9 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
<#---------------------------------------------------------------------------------------------------------------------------- | |
August 2017 - Robin Beismann - Michael Wessel Informationstechnologie GmbH | |
This script copys the CRLs from the different sites onto the DMZ Webserver(s) | |
config.xml may look like: | |
<Config> | |
<source share="<to be filled>" username="<to be filled>" password="<to be filled>"/> | |
<destination share="<to be filled>" username="<to be filled>" password="<to be filled>"/> | |
<destination share="<to be filled>" username="<to be filled>" password="<to be filled>"/> | |
</Config> | |
----------------------------------------------------------------------------------------------------------------------------#> | |
$curDir = (Get-Location).Path | |
$tempDir = $curDir + "\temp" | |
$sourceMap = "i:" | |
$destMap = "u:" | |
####################################################################################################################### | |
########################################### Do not modify below ####################################################### | |
####################################################################################################################### | |
#Define Varaibles | |
[xml]$config = Get-Content -Path ($curDir + "\config.xml") | |
$sources = $config.Config.source | |
$destinations = $config.Config.destination | |
#Check if Temp Directory exists (unclean script ending) | |
if(Test-Path($tempDir)){ | |
Remove-Item -Path $tempDir -Force -Confirm:$false -Recurse | |
} | |
#Create temp directory | |
New-Item -Path $tempDir -ItemType Directory | |
#Retrieve source files | |
foreach($source in $sources){ | |
#Map network drive | |
$net = New-Object -ComObject WScript.Network | |
$net.MapNetworkDrive($sourceMap, $source.share, $false, $source.username, $source.password) | |
#Copy Items | |
Get-ChildItem -Path ($sourceMap + "\*") -Include "*.crl" | ForEach-Object { | |
Copy-Item -Path $_.FullName -Destination $tempDir -Force -Confirm:$false | |
} | |
#Unmap network drive | |
$net.RemoveNetworkDrive($sourceMap,$true) | |
} | |
#Copy to destination(s) | |
foreach($destination in $destinations){ | |
#Map network drive | |
$net = New-Object -ComObject WScript.Network | |
$net.MapNetworkDrive($destMap, $destination.share, $false, $destination.username, $destination.password) | |
#Copy Items | |
Get-ChildItem -Path ($tempDir + "\*") -Include "*.crl" | ForEach-Object { | |
Copy-Item -Path $_.FullName -Destination ($destMap + "\") -Force -Confirm:$false | |
} | |
#Unmap network drive | |
$net.RemoveNetworkDrive($destMap,$true) | |
} | |
#Remove temp directory | |
Remove-Item -Path $tempDir -Force -Confirm:$false -Recurse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment