Files
PowerShell/scripts/list-network-shares.ps1
2025-07-21 11:37:30 +02:00

29 lines
740 B
PowerShell
Executable File

<#
.SYNOPSIS
Lists the network shares
.DESCRIPTION
This PowerShell script lists all network shares (aka "shared folders") of the local computer.
.EXAMPLE
PS> ./list-network-shares.ps1
✅ Shared folder \\LAPTOP\Public ("File transfer folder") -> D:\Public
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
if ($IsLinux) {
# TODO
} else {
$shares = Get-WmiObject win32_share | where {$_.name -NotLike "*$"}
foreach ($share in $shares) {
Write-Output "✅ Shared folder \\$(hostname)\$($share.Name) (`"$($share.Description)`") -> $($share.Path)"
}
}
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}