添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

But I can’t seem to combine them all. I want to see the driveletter (C) and get the other info for that drive on remote systems.

In the friendlyname, I have found that the description usually mentions NVMe if it’s an NVMe drive so even if the drive Mediatype is raid (designated in the bios), I can still see that its an NVMe drive (M.2)

Any suggestions?

Thank You

Terry

I have been unable to get it to work the way I want it to work (modifying the scripting etc).

Here’s the closest I’ve come:

$w = Invoke-command -computername acomputer -scriptblock  { 
$dInfo = Get-WmiObject Win32_logicaldisk -Filter 'DeviceId = "C:"' | Select DeviceID, DriveType
Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage  | Select FriendlyName, MediaType}
Clear-Variable Type
if($w.mediatype -eq 3) {$type = "HDD"}
if($w.mediatype -eq 4 -and $w.friendlyname -like "*NVMe*") {$type = "NVMe"}
if($w.mediatype -eq 4 -and $w.friendlyname -notlike "*NVMe*") {$type = "SSD"}
$type

I get the information from $dInfo and I get the proper information from $type (except it gives me all drives — I only need the C drive from $dInfo).

Is there a way to “Filter” results in [ Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage | Select FriendlyName, MediaType ] to show the results based on $dInfo.Drivetype ?

The overall objective is to have C: and the type show up

Thank You

Terry

You can use a hashtable or PSCustomObject to combine the information. For example:

Invoke-command -computername acomputer -scriptblock  { 
    $dInfo = Get-WmiObject Win32_logicaldisk -Filter 'DeviceId = "C:"' | 
        Select DeviceID, DriveType
    $w = Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage  | 
        Select FriendlyName, MediaType
    if($w.mediatype -eq 3) {
        $type = "HDD"
    if($w.mediatype -eq 4 -and $w.friendlyname -like "*NVMe*") {
        $type = "NVMe"
    if($w.mediatype -eq 4 -and $w.friendlyname -notlike "*NVMe*") 
        $type = "SSD"
    [PSCustomObject]@{
        Type=$type
        DriveLetter=$dinfo.DeviceID
              

When I run this independently, it works great, however, when I put it in my production script, it partially breaks.

#================= Drive Type ==============================
$GetDriveInfo = Invoke-command -computername $HostName -scriptblock  { 
$dInfo = Get-WmiObject Win32_logicaldisk -Filter 'DeviceId = "C:"' | Select DeviceID, DriveType
Get-WmiObject -Class MSFT_PhysicalDisk -Namespace root\Microsoft\Windows\Storage  | Select FriendlyName, MediaType}
Clear-Variable Type
if($GetDriveInfo.mediatype -eq 3) {
    $type = "HDD"
if($GetDriveInfo.mediatype -eq 4 -and $GetDriveInfo.friendlyname -like "*NVMe*") {
$type = "NVMe"
if($GetDriveInfo.mediatype -eq 4 -and $GetDriveInfo.friendlyname -notlike "*NVMe*") {
$type = "SSD"
$CombInfo = [PSCustomObject]@{
        Type=$type
        DLetter= $dinfo.DeviceID
$Dtype = -Join ($CombInfo.DLetter," Drive is an ",$type," Drive")  #
#================End Drive Type ============================

In the Custom Object, when I highlight $info.DeviceID, I get “C:”. When I highlight $CombInfo.DLetter, I get C:

When I highlight $Dtype, I get " C: Drive is an NVMe Drive". So, all this gives me the proper info, however when I use $Dtype elsewhere in my script, “C:” shows up blank; I only see " Drive is an NVMe Drive". Same thing happens when I use $dinfo.DeviceID; the “C:” does not show up.

Any suggestions?

I have checked out the scoping in my script and there seems to be no reason it does not show up.

Thank You

Terry