Author Posts

October 5, 2017 at 4:28 pm

Hey Everyone,

I am looking to get a list of all of our users and their mapped network drives.
So far I have a script to get my network drives. Any thoughts?

Get-WmiObject -Class Win32_MappedLogicalDisk | select Name, ProviderName

October 5, 2017 at 8:53 pm

You of course have to run that command line on each computer in your AD environment
With PowerShell Remoteing enabled and if you have admin privileges to the hosts. You can just do.

( Get-ADComputer -Filter * ).Name `
| % { Invoke-Command -ComputerName $_ `
-ScriptBlock { Get-WmiObject -Class Win32_MappedLogicalDisk `
| select Name, ProviderName }}

Or something like...

Function Get-RemoteHostMappedDrives
{
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, HelpMessage="Specify the Get-ADComputer name filter to apply (Use * for wildcard")]
[string] $TargetHost
)

"Showing mapped on $TargetHost"

$Mapped = Get-WmiObject -class "Win32_MappedLogicalDisk" `
-namespace "root\CIMV2" `
-computername $TargetHost `
| Select DeviceID,ProviderName

ForEach ($drive in $mapped)
{ $drive.DeviceID, $drive.ProviderName }
}

Get-RemoteHostMappedDrives -TargetHost *

October 5, 2017 at 9:21 pm

Hmmm ... if I'm not wrong that wouldn't work as you probably expect it. You have to run this commands in the context of logged on user. If you do it with Powershell remoting you would only get the mapped drives of the account you use to access the clients.

October 6, 2017 at 3:11 pm

try something like this

$ComputerName = "computername"

gwmi win32_mappedlogicaldisk -ComputerName $ComputerName | select SystemName,Name,ProviderName,SessionID | foreach {
$disk = $_
$user = gwmi Win32_LoggedOnUser -ComputerName $ComputerName | where { ($_.Dependent.split("=")[-1] -replace '"') -eq $disk.SessionID} | foreach {$_.Antecedent.split("=")[-1] -replace '"'}
$disk | select Name,ProviderName,@{n="MappedTo";e={$user} }
}