-
-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathlist-network-shares.ps1
More file actions
executable file
·32 lines (31 loc) · 877 Bytes
/
list-network-shares.ps1
File metadata and controls
executable file
·32 lines (31 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
.SYNOPSIS
List network shares
.DESCRIPTION
This PowerShell script lists all network shares (aka "shared folders") of the local computer.
.EXAMPLE
PS> ./list-network-shares.ps1
✅ Shared \\LAPTOP\Public folder from D:\Public ('File transfer folder')
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
try {
if ($IsLinux -or $IsMacOS) {
# TODO
} else {
$shares = Get-WmiObject win32_share | where {$_.name -NotLike "*$"}
foreach ($share in $shares) {
if ($share.Description -eq "") {
Write-Host "✅ Shared \\$(hostname)\$($share.Name) from $($share.Path)"
} else {
Write-Host "✅ Shared \\$(hostname)\$($share.Name) from $($share.Path) ('$($share.Description)')"
}
}
}
exit 0 # success
} catch {
"⚠️ ERROR: $($Error[0]) (script line $($_.InvocationInfo.ScriptLineNumber))"
exit 1
}