Mapped drives for all users in Domain

This topic contains 3 replies, has 4 voices, and was last updated by  Simon B 1 week, 5 days ago.

  • Author
    Posts
  • #81389

    Rocky Ramirez
    Participant

    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

    postanote
    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
    {
    [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 *

    • #81422

      Olaf Soyk
      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

    Simon B
    Participant

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

You must be logged in to reply to this topic.