0

I'm writing a little powershell script for some basic logs that have to be generated. Right now I'm stuck with logging mapped network drives:

$colDrives = Get-WmiObject Win32_MappedLogicalDisk -ComputerName localhost
foreach ($objDrive in $colDrives) {
    $array += $objDrive.DeviceID + $objDrive.ProviderName
}

This code works fine with mounted network drives that are connected. But I'm more interested in mapped drives that are not working. A net use on a cmd prompt shows me a status column, I'd like to have this too in a similar way

Z:\server\path should be Z:\server\path (ok|dead)

Regards, Alessandro

1 Answers1

0

Try Test-Path -LiteralPath $objDrive.DeviceID or Test-Path -LiteralPath $objDrive.ProviderName.

Example with Select-Object and calculated property:

$colDrives = Get-WmiObject Win32_MappedLogicalDisk -ComputerName localhost
foreach ($objDrive in $colDrives) {
    $array += $objDrive |
        Select-Object DeviceID, ProviderName, @{
            Name = 'Online'
            Expression = {[bool](Test-Path -LiteralPath $objDrive.DeviceID)}
        }
}
beatcracker
  • 1,359
  • 8
  • 13