Here the first script seems to work exactly like the second script.
But when restoring the drive with Acronis I get the message a reboot is required to complete the operation. However the second script has no such message, just restore is complete.
This isn’t an acronis question, rather how to tweak the pure powershell script do match the diskpart script. I thought I had it the same. But something isn’t right with it because I shouldn’t get the reboot required message.
First script:
Get-Disk | Sort-Object -Property DiskNumber
# Define target disk number (Change 0 to the correct disk number if necessary!)
$diskNumber = Read-Host -Prompt "Enter the Disk Number (e.g., 0, 1, 2)"
#$diskNumber = 1
# Define partition sizes (in MB)
$efiSize = 500
$msrSize = 128
$recoverySize = 2048 # Can be adjusted
Write-Host "WARNING: All data on Disk $diskNumber will be erased."
Read-Host "Press Enter to continue or Ctrl+C to cancel."
# Clear the disk, initialize as GPT
Clear-Disk -Number $diskNumber -RemoveData -RemoveOEM -Confirm:$false
Initialize-Disk -Number $diskNumber -PartitionStyle GPT
# Create EFI, MSR, and Windows partitions
New-Partition -DiskNumber $diskNumber -Size ($efiSize * 1MB) -GptType "{c12a7328-f81f-11d2-ba4b-00a0c93ec93b}" -AssignDriveLetter | Format-Volume -FileSystem FAT32 -NewFileSystemLabel "SYSTEM"
New-Partition -DiskNumber $diskNumber -Size ($msrSize * 1MB) -GptType "{e3c9e316-0b5c-4db8-817d-f92df00215ae}"
$windowsPartition = New-Partition -DiskNumber $diskNumber -UseMaximumSize -AssignDriveLetter | Format-Volume -FileSystem NTFS -NewFileSystemLabel "Windows"
# Shrink Windows partition and create Recovery partition
$winPartition = Get-Partition -DriveLetter $windowsPartition.DriveLetter
Resize-Partition -DriveLetter $winPartition.DriveLetter -Size ($winPartition.Size - (2056 * 1MB))
$recoveryPartition = New-Partition -DiskNumber $diskNumber -Size (2048 * 1MB) | Format-Volume -FileSystem NTFS -NewFileSystemLabel "WinRE_DRV"
# Set Recovery partition type and hide it
Set-Partition -PartitionNumber $recoveryPartition.PartitionNumber -DiskNumber $diskNumber -GptType "{DE94BBA4-06D1-4D40-A16A-BFD50179D6AC}"
Set-Partition -PartitionNumber $recoveryPartition.PartitionNumber -DiskNumber $diskNumber -IsHidden $true
Write-Host "Partitioning complete. Windows partition is assigned drive letter $($windowsPartition.DriveLetter)"
Read-Host "Press Enter to finish."
Second script works perfect:
Get-Disk
$diskNumber = Read-Host -Prompt "Enter the disk number (e.g., 2, 3, 4)"
Write-Host "Disk number $diskNumber chosen, if wrong hit CTRL-C now !!!!!!!!!!!!!!!!!!"
Read-Host -Prompt "Or press Enter to continue..."
$diskpart_commands = @"
select disk $diskNumber
clean
convert gpt
create partition efi size=500
format quick fs=fat32 label="SYSTEM"
create partition msr size=128
create partition primary
shrink minimum=2056
format quick fs=ntfs label="Windows"
create partition primary size=2048
format quick fs=ntfs label="WinRE_DRV"
assign letter="R"
set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
gpt attributes=0x8000000000000001
list vol
exit
"@
$diskpart_commands | diskpart.exe
Read-Host -Prompt "Done press Enter to continue..."
Any tips appreciated.
Edit:
I even tried taking out the -AssignDriveLetter for the efi partition.
I just want a powershell script that will work like the diskpart script. No errors are thrown however something is not working correctly.
After running the script a diskpart sel disk the list part shows all partitions correctly created.
However there is something wrong where Acronis requires a reboot to fix. But the diskpart script Acronis just shows the recovery succeeded message.