Mapped drives for all users in Domain

Welcome Forums General PowerShell Q&A Mapped drives for all users in Domain

This topic contains 3 replies, has 4 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #81389

    Points: 0
    Rank: Member

    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

  • #81419

    Points: 208
    Helping Hand
    Rank: Participant

    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
    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 *

    • #81422

      Points: 144
      Helping Hand
      Rank: Participant

      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.

  • #81481

    Points: 13
    Rank: Member

    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} }

The topic ‘Mapped drives for all users in Domain’ is closed to new replies.