Converting .bak file format to VHd using Powershell

Hi,

I have tried using convert-vhd file in power shell scripting to convert a back up file to vhd format but in vain. Can someone please tell me the steps to follow it or any built in function to do the task.

 

Thanks

If you show us what you’ve tried and where it’s not working/errors received, then i’m sure we can help you figure it out.

[quote quote=225549]If you show us what you’ve tried and where it’s not working/errors received, then i’m sure we can help you figure it out.

[/quote]

#Get-DbaDiskSpace -ComputerName DESKTOP-RAQK42T
$input = Read-Host -Prompt ‘Enter Directory Name:’
$input1 = Read-Host -Prompt ‘Enter Folder Name:’
New-Item -Path “$input” -Name “$input1” -ItemType “directory”
echo $input
echo $input1

Variable

$Server = ‘DESKTOP-RAQK42T’
$Database = ‘db_airport’
$BackupFolder = “$input” + “$input1”
#$dt = Get-Date -Format yyyy-mm-dd /Get today date/
#$FilePath = “$($BackupFolder)$($Database)db$($dt).bak”
$FilePath = “$($BackupFolder)$($Database).bak”

#For Backup
Backup-SqlDatabase -ServerInstance $Server -Database $Database -BackupFile $Filepath

#After taking a backup (.bak) from SQL server 2017 . I am intending to convert or build an image .vhdx (Hard disk image file). Using this .vhdx file i wan to create a container . I am new to powershell and need little help. Thanks

So this works to create your backup fine, I assume. Now you are wanting a container with the contents of the backup? Maybe i’m misunderstanding, but wouldn’t you just want to spin up a SQL container, and then restore your backup?

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash

https://hub.docker.com/_/microsoft-mssql-server

Perhaps you can provide clarity on what exactly you’re intending to do with the VHD. Since it’s a SQL backup file, I imagine you’re wanting to either access the data within or verify it’s integrity.

[quote quote=225570]So this works to create your backup fine, I assume. Now you are wanting a container with the contents of the backup? Maybe i’m misunderstanding, but wouldn’t you just want to spin up a SQL container, and then restore your backup?

https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash

https://hub.docker.com/_/microsoft-mssql-server

Perhaps you can provide clarity on what exactly you’re intending to do with the VHD. Since it’s a SQL backup file, I imagine you’re wanting to either access the data within or verify it’s integrity.

[/quote]
For clarity:

Thanks for your valuable feedback. the link you provided is used to create the container. but I am stuck to build an image from the .bak file.

I have multiple backups (.bak). I want to build an image for all backups and after using this image file I want to create a windocks container that includes (container name, port, and password). so that I assign the container to a different department in the organization. The steps are : (taking backups > build image>create a windocks container)

I want to automate all these steps using PowerShell.