+$currDaytime = Get-Date -format "yyyyMMdd-HHmmss"
+
+$databases = Get-Databases | Where-Object {!($_ -in $defaultExclusions -or $_ -in $configDbExclusions)}
+
+$databasesToBackup = @()
+
+if($configDbBackup -and $configDbBackup.count -gt 0) {
+ $databasesToBackup = $configDbBackup
+}
+else {
+ $databasesToBackup = $databases
+}
+
+foreach($d in $databasesToBackup) {
+ $databaseBackupDir = Join-Path -Path $configBackupDir -ChildPath $d
+
+ if(!(Test-Path $databaseBackupDir)) {
+ New-Item -ItemType directory -Path $databaseBackupDir -ErrorAction Stop | Out-Null
+ }