gpt4 book ai didi

powershell - 如何在不知道VHD路径的情况下删除分区访问路径

转载 作者:行者123 更新时间:2023-12-03 07:49:12 25 4
gpt4 key购买 nike

我使用 Powershell Add-PartitionAccessPath 将 VHDX 文件中的分区映射到 c:\temp\mysupport 文件夹。

我正在尝试创建一个将访问路径作为输入参数的函数并将其删除。我看到Remove-PartitionAccessPath 可用。但它希望您传递磁盘号、分区号等。

想知道是否有办法将文件夹安装点映射回分区对象、磁盘对象等以将其删除。

最佳答案

稍微谷歌一下,我找到了一种方法。事情并不是那么简单。博客文章Locating Mount points帮助我想出了这个片段。

下面是代码片段:

# Make sure the path is absolute path ending with \. 
# If the path doesn't end \, the filter logic
# on Get-WmiObject won't work
$dirMount="$($ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($dirMount))\"
$aVol = Get-WmiObject Win32_Volume | Where-Object -FilterScript {$_.Caption -eq "$dirMount"}
if (-not $aVol)
{
echo "ERROR: [$($MyInvocation.MyCommand)] Unable to map $dirMount to a volume"
return $false
}
$volID = $aVol.DeviceID
if ($volID)
{
$aVol = Get-Volume -UniqueId "$volID" |Get-Partition|Remove-PartitionAccessPath -AccessPath "$dirMount"
$result = ($aVol -eq $null)
}

关于powershell - 如何在不知道VHD路径的情况下删除分区访问路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73345879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com