Created
June 1, 2016 15:21
-
-
Save christopherbauer/48d1f4a081abb707842a0e49095235cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $source = "C:\Scripts" | |
| $archiveDestination = "C:\ScriptsArchive" | |
| $type = "ps1" | |
| $offsiteDrive = "M" | |
| #Create mapping if missing | |
| .\Map-Azure.ps1 -DriveLetter "$offsiteDrive" -StorageKey "[storage key]" | |
| #Copy files to Archive | |
| .\Migrate-Files.ps1 -Source "$source\*.$type" -Destination $archiveDestination | |
| #Remove items that are not from todays backup | |
| $date = Get-Date -Format yyyyMMdd | |
| Remove-Item -Path "${archiveDestination}\*.$type" -exclude "*$date*" | |
| #Move files to storage account. They will be destroyed | |
| .\Migrate-Files.ps1 -Source "$source\*.$type" -Destination "${offsiteDrive}:\" -Remove | |
| #Remove remote backups that are not from todays backup | |
| $date = Get-Date -Format yyyyMMdd | |
| Remove-Item -Path "${offsiteDrive}:\*.$type" -exclude "*$date*" |
This file contains hidden or 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
| param ( | |
| [string]$DriveLetter, | |
| [string]$StorageKey | |
| ) | |
| if (!(Test-Path "${DriveLetter}:")) | |
| { | |
| cmd.exe /c "net use ${DriveLetter}: \\[storage folder location] /u:[username] ""${StorageKey}""" | |
| } |
This file contains hidden or 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
| param( | |
| [string]$Source, | |
| [string]$Filter, | |
| [string]$Destination, | |
| [switch]$Remove=$False | |
| ) | |
| #Test if source path exist | |
| if((Test-Path -Path $Source.trim()) -ne $True) { | |
| throw 'Source did not exist' | |
| } | |
| #Test if destination path exist | |
| if ((Test-Path -Path $Destination.trim()) -ne $True) { | |
| throw 'Destination did not exist' | |
| } | |
| #Test if no files in source | |
| if((Get-ChildItem -Path $Source).Length -eq 0) { | |
| throw 'No files at source' | |
| } | |
| if($Remove) | |
| { | |
| #Move-Item removes the source files | |
| Move-Item -Path $Source -Filter $Filter -Destination $Destination -Force | |
| } else { | |
| #Copy-Item keeps a local copy | |
| Copy-Item -Path $Source -Filter $Filter -Destination $Destination -Force | |
| } | |
| return $True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment