-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample3.ps1
59 lines (43 loc) · 1.32 KB
/
sample3.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
48
49
50
51
52
53
54
55
56
57
58
59
#requires -module SMBShare
Return "This is a walkthrough demo"
#be sure to document
Function Get-ShareData {
[cmdletbinding()]
Param(
[string]$Name,
[string]$Computername = $env:COMPUTERNAME
)
#save existing value if found
if ($PSDefaultParameterValues.ContainsKey("Write-Host:foregroundcolor")) {
$saved = $PSDefaultParameterValues."Write-host:foregroundcolor"
}
$PSDefaultParameterValues.Add("Write-Host:foregroundcolor","cyan")
write-Host "Getting share $Name from $computername"
$share = Get-SMBShare -Name $Name -CimSession $Computername
$sharepath = $share.path
write-host "Measuring files in $sharePath"
$stats = Invoke-Command {
get-childitem -path $using:sharepath -file -Recurse |
Measure-Object -Property length -sum
} -computername $Computername
Write-Host "Found $($stats.count) files"
[pscustomobject]@{
Name = $share.Name
Description = $share.Description
Path = $Sharepath
Files = $stats.count
Size = $stats.Sum
Date = (Get-Date).ToShortDateString()
Computername = $share.pscomputername.toUpper()
}
if ($saved) {
$PSDefaultParameterValues."Write-host:foregroundcolor" = $saved
}
else {
$PSDefaultParameterValues.remove("Write-host:foregroundcolor")
}
} #close function
$PSDefaultParameterValues.Clear()
$PSDefaultParameterValues
Get-ShareData -Name Work
$PSDefaultParameterValues