简体   繁体   English

使用 PowerShell 为 CD 驱动器分配驱动器号

[英]Assign drive letter to CD-Drive using PowerShell

I have a CD drive, without a drive letter, because I am trying to automatically rearrange Volumes.我有一个没有盘符的 CD 驱动器,因为我正在尝试自动重新排列卷。 I want to use PowerShell a drive letter to the CD drive (here ISOIMAGE).我想使用 PowerShell 一个盘符到 CD 驱动器(这里是 ISOIMAGE)。

磁盘管理图片

I removed it using the following:我使用以下方法删除了它:

$cdDrive = Get-WmiObject -Class Win32_volume -Filter 'DriveType=5' | Select-Object -First 1
$cdDrive | Set-WmiInstance -Arguments @{ DriveLetter = $null }

I assumed that something like this would therefore work:我认为这样的事情会因此起作用:

$cdDrive | Set-WmiInstance -Arguments @{ DriveLetter = "F:\" }

To my confusion, PowerShell responded like this:令我困惑的是,PowerShell 是这样回应的:

Set-WmiInstance: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. Set-WmiInstance:输入 object 不能绑定到命令的任何参数,因为命令不采用管道输入,或者输入及其属性与采用管道输入的任何参数都不匹配。

I also tried:我也试过:

Get-Volume | ? DriveType -eq "cd-rom" | Set-WmiInstance -Arguments @{ DriveLetter = "F:\" };
Get-Volume | ? DriveType -eq "cd-rom" | Set-WmiInstance -Arguments @{ DriveLetter = "F:\"; Label="bruh" };
Get-Volume | ? DriveType -eq "cd-rom" | Set-Partition -NewDriveLetter "F";

It turns out $cdDrive has a method called AddMoundPoint , so $cdDrive.AddMountPoint("F:") worked.原来$cdDrive有一个名为AddMoundPoint的方法,所以$cdDrive.AddMountPoint("F:")起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM