Could someone proficient in PowerShell assist with troubleshooting a complex single-line command?

Copper Contributor

I'm currently working on a command that will be integrated into a batch file. The command aims to change the MBR partition type IDs of the first two partitions on each drive, specifically based on the presence of certain files on the root of the partitions.

 

The initial command I have already put together successfully changes the partition type IDs. However, I am now looking to refine the command to include a check for the presence of files named VOL1_M_MEDIA.WIM and VOL2_M_MEDIA.WIM on the root of the partitions before making the type changes.

 

This is the improved command that I am testing, but it has not been effective thus far. Although the command completes without errors, the partition type is not updated despite the specified files being present:

 

```powershell.exe -executionpolicy bypass -command "Get-Disk | Get-Partition | Where-Object { $_.PartitionNumber -eq 1 -and $_.mbrtype -eq '0x0c' -and (Test-Path '\\$($_.UniqueId)\\VOL1_M_MEDIA.WIM') } | Set-Partition -mbrtype '0x1c'; Get-Disk | Get-Partition | Where-Object { $_.PartitionNumber -eq 2 -and $_.mbrtype -eq '0x07' -and (Test-Path '\\$($_.UniqueId)\\VOL2_M_MEDIA.WIM') } | Set-Partition -mbrtype '0x17'"`

``` 

 

Please note that the intention is for the command to dynamically find the specified files without relying on specific drive letters.

0 Replies