-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-smbshare.ps1
48 lines (35 loc) · 1.2 KB
/
find-smbshare.ps1
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#smb finder
function find-smbshare {
param ([string]$server )
begin {
Add-Type -Language CSharp @"
public class smbshare{
public string name;
public string type;
public string host;
public string path;
}
"@
$ct=Test-Connection -Count 1 -Quiet -computername $server
}#end begin
process{if (!$ct) {Write-Error ('computer unavalible: '+$server)
}
if($ct){
$smb=net.exe view $server
$smb=$smb[7..($smb.count-3)]
$mat=$smb -match "\s{3,}"#filter out junk
$re=$mat -replace "\s+",";"#ready for split
$re.foreach{ {$split=$_.split(';') #split and make obj if server is available
$sharename=$split[0]
$sharetype=$split[1]
$smb_ob=New-Object -TypeName smbshare
$smb_ob.host= $server
$smb_ob.name=$sharename
$smb_ob.path=('\\'+$server+'\'+$sharename)
$smb_ob.type=$sharetype
Write-Output $smb_ob
}
}
}#end process
}#end if
}#end func