Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does powershell not support add-partitionaccesspath and set-partition commands

The add-partitionaccesspath and set-partition command is not supported as shown below.

> add-partitionaccesspath -disknumber 2 -partitionnumber 0 -accesspath g:
add-partitionaccesspath : Not Supported

> set-partition -disknumber 2 -partitionnumber 0 -newdriveletter i
set-partition : Not Supported

But I can get information about add-partitionaccesspath and set-partition commands using get-help command.

> get-help add-partitionaccesspath
NAME
    Add-PartitionAccessPath

> get-help set-partition
NAME
    Set-Partition

I would like some help as to why the add-partitionaccesspath and set-partition commands are not supported.

like image 535
7_tree Avatar asked Dec 16 '25 22:12

7_tree


2 Answers

I got this error using Add-PartitionAccessPath because I tried to create an access path to an offline disk. The disk was offline, because I had mounted two differencing .avhdx (snapshot) files that were linked to the same base .vhdx file.

Mounting the first .avhdx file created an online disk, but mounting the second one created an offline disk. Apparently two .avhdx files, that are linked to the same base file, can't be online at the same time, even if you mount them both with -ReadOnly flag.

Repro

This assumes that both .avhdx files are linked to the same base .vhdx file.

$vhd1 = Mount-VHD 'C:\…\Disk1.avhdx' -ReadOnly -NoDriveLetter -Passthru
$vhd2 = Mount-VHD 'C:\…\Disk2.avhdx' -ReadOnly -NoDriveLetter -Passthru

# List the online status of the mounted disks
$vhd1, $vhd2 | Get-Disk | Select Number, OperationalStatus

# Try to create access paths for both disks
$vhd1 | Get-Disk | Get-Partition | Where Type -eq Basic | Add-PartitionAccessPath -AccessPath (New-Item c:\Access1 -ItemType Directory -Force)
$vhd2 | Get-Disk | Get-Partition | Where Type -eq Basic | Add-PartitionAccessPath -AccessPath (New-Item c:\Access2 -ItemType Directory -Force)

Output:

Number OperationalStatus
------ -----------------
     3 Online
     4 Offline

Add-PartitionAccessPath : Not Supported
At Line:1 Char:59
+ ... ere Type -eq Basic | Add-PartitionAccessPath -AccessPath (New-Item c:\Access2 ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (StorageWMI:ROOT/Microsoft/.../MSFT_Partition) [Add-PartitionAccessPath], CimException
    + FullyQualifiedErrorId : StorageWMI 1,Add-PartitionAccessPath

Solution

Dismount the 1st .avhdx file before mounting the 2nd .avhdx file:

# Mount the first VHD
$vhd1 = Mount-VHD 'C:\…\Disk1.avhdx' -ReadOnly -NoDriveLetter -Passthru

# Create access path for partition of first disk
$partition1 = $vhd1 | Get-Disk | Get-Partition | Where Type -eq Basic
$partition1 | Add-PartitionAccessPath -AccessPath (New-Item c:\Access1 -ItemType Directory -Force)

# Work with the files of the VHD through the access path
Get-ChildItem c:\Access1

# Remove partition access path
$partition1 | Remove-PartitionAccessPath -AccessPath c:\Access1

# Dismount
$vhd1 | Dismount-VHD

# Mount the second VHD
$vhd2 = Mount-VHD 'C:\…\Disk2.avhdx' -ReadOnly -NoDriveLetter -Passthru

# Repeat above steps for the 2nd disk…

Depending on your use case, you could alternatively manage the online status of the disks using Set-Disk -IsOffline, without dismounting. It still doesn't allow you to set both disks online though, you have two switch one to offline status first.

# Assuming both disks are already mounted, we have finished working
# with $vhd1 and now want to use $vhd2

# Force disk1 to offline
$vhd1 | Get-Disk | Set-Disk -IsOffline $true

# Force disk2 to online
$vhd2 | Get-Disk | Set-Disk -IsOffline $false

# Should succeed now
$vhd2 | Get-Disk | Get-Partition | Where Type -eq Basic | Add-PartitionAccessPath -AccessPath (New-Item c:\Access2 -ItemType Directory -Force)
like image 140
zett42 Avatar answered Dec 19 '25 19:12

zett42


The Add-PartitionAccessPath and Set-Partition commands can be used when the drive has an NTFS file system. You are probably using an external memory to run these commands and the file system is FAT32; I assumed because the drive letter specified with the -accesspath flag is g:. The Add-PartitionAccessPath command's reference document states the supported file system. 1


Footnotes

1. Mounted folders are supported only on NTFS-formatted partitions.


References
  • Add-PartitionAccessPath - Notes Section
like image 41
Sercan Avatar answered Dec 19 '25 19:12

Sercan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!