Additional SQL Server features and topics not covered by specific categories
Hi @Ashwan ,
Sorry that I am not very good at PowerShell, and cannot help you to change the code.
But, as Dirk said, you can use the Powershell module dbatools, which can more easily and conveniently meet your requirements.
For example:
Install-Module dbatools
Import-Module dbatools
$TargetSqlServerInstance = ‘wx-80490’
$TargetDb= ‘RefreshTest’
$BackupFile = ‘C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Backup\RefreshTest.bak’
$DestinationDataDirectory = "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA”
$DestinationLogDirectory = "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA"
Restore-DbaDatabase -SqlInstance $TargetSqlServerInstance -Path $BackupFile -DestinationDataDirectory $DestinationDataDirectory -DestinationLogDirectory $DestinationLogDirectory -WithReplace -DatabaseName $TargetDb -ReplaceDbNameInFile
In addition, you can add a windows-server-powershell tag to this thread so that people there will help you more effectively.
Best Regards,
Amelia
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
What can I do if my transaction log is full?--- Hot issues November
How to convert Profiler trace into a SQL Server table -- Hot issues November