Skip to content

Instantly share code, notes, and snippets.

@RIKIKU
Last active June 30, 2016 03:08
Show Gist options
  • Save RIKIKU/4e5f6e11629f130287d90b8f2562e06c to your computer and use it in GitHub Desktop.
Save RIKIKU/4e5f6e11629f130287d90b8f2562e06c to your computer and use it in GitHub Desktop.
$BackupFilesLocation = '\\MyfileServer\MyBackupsFolder'
$DBPATHS = Get-ChildItem -Recurse $BackupFilesLocation
#$DBPATH.FullName
$OutputArray =@()
foreach ($DBPATH in $DBPATHS){
$namesnstuff = New-Object psobject -Property @{
BaseName = $DBPATH.BaseName -replace "_backup.*"
FullName = $DBPATH.FullName
}
$OutputArray += $namesnstuff
}
$OutputArray | Export-Csv "$BackupFilesLocation\FileList.csv" -NoTypeInformation
<#
Below is the formula to use in excel.
="RESTORE DATABASE " & B2 & " FROM DISK = '" & A2 & "' WITH MOVE 'mscrm' TO 'E:\MSSQL10_50.SOL\MSSQL\DATA\"&B2&".MDF', MOVE 'mscrm_log' TO 'E:\MSSQL10_50.SOL\MSSQL\DATA\"&B2&".LDF'"
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment