How do I get disconnected networkdrives in Powershell? How do I get disconnected networkdrives in Powershell? powershell powershell

How do I get disconnected networkdrives in Powershell?


while the HKCU path solution posted by James C. is likely a better solution, you CAN get the output of net use into objects. lookee ...

net use |    Select-Object -SkipLast 2 |    Select-Object -Skip 6 |    ForEach-Object {$_ -replace '\s{2,}', ', '} |    ConvertFrom-Csv -Header Status, DriveLetter, UNC_Path, Network |    Select-Object -Property DriveLetter, UNC_Path

hope that helps,
lee


You can get the status of network drives from the Users registry using:

Get-ChildItem hkcu:\network

To access these reg entries you need to use Get-ItemProperty, you can build a PSObject to hold the properties to make this nicer:

Get-ChildItem hkcu:\network | %{                $obj = New-Object PSObject    $obj | Add-Member Noteproperty Drive $_.name.Replace('HKEY_CURRENT_USER\network\','')    $obj | Add-Member NoteProperty Path (Get-ItemProperty (Join-Path hkcu:\network $_.name.split('\')[-1]) | Select-Object -ExpandProperty RemotePath)    [array]$mapped += $obj}

Example properties:

PS> $mappedDrive Path          ----- ----          Y     \\server1\shareZ     \\server2\hidden$