Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virt-v2v: Replace the Get-Disk and Set-Disk with diskpart #991

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions virt-v2v/cold/scripts/windows/9999-restore_config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,28 @@ Write-Output ('') >> $logFile

# script section to re-enable all offline drives
# Re-enable all offline drives
Write-Output ('Re-enabling all offline drives') >> $logFile
Get-Disk | Where { $_.FriendlyName -like '*VirtIO*' } | % {
Write-Output (' - ' + $_.Number + ': ' + $_.FriendlyName + '(' + [math]::Round($_.Size/1GB,2) + 'GB)') >> $logFile
$_ | Set-Disk -IsOffline $false
$_ | Set-Disk -IsReadOnly $false

# Get all disks that match the filter using Win32_DiskDrive
$disks = Get-WmiObject -Query "SELECT * FROM Win32_DiskDrive WHERE Model LIKE '%VirtIO%'"

# Check if any disks were found
if ($disks.Count -eq 0) {
Write-Output ("No disks found matching the filter 'VirtIO'.") >> $logFile
} else {
# Iterate through each matching disk
foreach ($disk in $disks) {
$diskNumber = $disk.Index # Get the disk index which corresponds to the disk number

# Create a diskpart script to set the disk online
$diskpartScript = @"
select disk $diskNumber
online disk
attributes disk clear readonly
"@
Comment on lines +18 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels quie risky to me.

Take an index from one tool/api, and use it in a different tool/api.

This is just waiting for indexes to be out of sync for whatever reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree and I would like to not use the diskpart


# Execute the diskpart script
$diskpartScript | diskpart

Write-Output ("Disk $($disk.Model) (Disk Number: $diskNumber) is now online.") >> $logFile
}
}
Write-Output ('') >> $logFile
Loading