Last active
May 10, 2022 19:10
-
-
Save soulhakr/0992443a8c30278d30e9 to your computer and use it in GitHub Desktop.
[Get Mapped Drives (Powershell)] An easy way to determine a remote host's active user's current drive mappings. #windows #utility #powershellcore #powershell #pwsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-MappedDrive { | |
<# | |
.SYNOPSIS | |
Returns the active drive mappings of a hosts current user session | |
.DESCRIPTION | |
Get-MappedDrive is a function which (optionally) takes a remote host and returns the active drive mappings the current user session | |
.PARAMETER ComputerName | |
Specifies a remote host | |
.EXAMPLE | |
Get-MappedDrive [-ComputerName <Remote Host>] | |
.INPUTS | |
String | |
.OUTPUTS | |
PSCustomObject | |
.NOTES | |
Author: Dave Edwards | |
Twitter: @soulhakr | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory=$false)] | |
[Alias("w")] | |
[string] $ComputerName | |
) | |
$hostname = if ($PSBoundParameters.ContainsKey('ComputerName') -and (-not [String]::IsNullOrEmpty($ComputerName))) { | |
$ComputerName | |
} else { | |
(Get-CimInstance -ClassName CIM_ComputerSystem).Name | |
} | |
Write-Host "Drives currently mapped on $($hostname):" | |
Get-CimInstance -ClassName 'Win32_MappedLogicalDisk' -Namespace 'root\CIMV2' -ComputerName $hostname | Select-Object -Property DeviceID, ProviderName, Name, Caption, Description | Format-Table -AutoSize | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment