forked from PowerShell/SHiPS
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathShowProgress.psm1
More file actions
130 lines (86 loc) · 3.02 KB
/
Copy pathShowProgress.psm1
File metadata and controls
130 lines (86 loc) · 3.02 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<#
Assuming you have done git clone and run build.ps1, cd to your git clone folder and try the following.
Import-Module SHiPS
Import-Module .\samples\ShowProgress.psm1
new-psdrive -name m -psprovider SHiPS -root ShowProgress#BuiltinProgress
cd m:
dir
dir -verbose
cd c:\
new-psdrive -name n -psprovider SHiPS -root ShowProgress#NoBuiltinProgress
cd n:
dir -verbose
#>
using namespace Microsoft.PowerShell.SHiPS
[SHiPSProvider(UseCache=$true)]
class BuiltinProgress : SHiPSDirectory
{
Hidden [object]$data = $null
BuiltinProgress([string]$name): base($name)
{
}
[object[]] GetChildItem()
{
$obj = @()
Write-verbose "hello, you specified -verbose." -Verbose
Write-warning "hello, this is the Warning information."
Write-debug "hello, this is the debug information."
$activityMessage ="This is a demo to show you how to use Write-Progress for long running operations"
$count=1
$id = 5 # random number
$parentId = 1 # builtin progressid=1
While($count -lt 3)
{
$count++
Write-Progress -Id $id -ParentId $parentId -Activity $activityMessage -PercentComplete $count
Start-Sleep -Seconds 1
$ps=get-process powershell | Select-Object -First 1
Write-warning "hello$count Warning info"
Write-debug "hello$count debug info"
$obj += [ABCLeaf]::new($ps.Name + $count, $ps);
Write-verbose "hello$count verbose info"
}
Write-Progress -Id $id -ParentId $parentId -Activity $activityMessage -Completed
return $obj;
}
}
[SHiPSProvider(BuiltinProgress= $false)]
class NoBuiltinProgress : SHiPSDirectory
{
Hidden [object]$data = $null
NoBuiltinProgress([string]$name): base($name)
{
}
[object[]] GetChildItem()
{
$obj = @()
Write-verbose "hello, you specified -verbose."
Write-warning "hello, this is the Warning information."
Write-debug "hello, this is the debug information."
$activityMessage ="This is a demo to show you how to use Write-Progress for long running operations"
$count=1
$id = 50 # random number
$parentId = 1 # random number
While($count -lt 3)
{
$count++
Write-Progress -Id $id -Activity $activityMessage -PercentComplete $count -ParentId $parentId
Start-Sleep -Seconds 1
$ps=get-process powershell | Select-Object -First 1
Write-warning "hello$count Warning info"
Write-debug "hello$count debug info"
$obj += [ABCLeaf]::new($ps.Name + $count, $ps);
Write-verbose "hello$count verbose info"
}
Write-Progress -Id $id -Activity $activityMessage -Completed
return $obj;
}
}
class ABCLeaf : SHiPSLeaf
{
Hidden [object]$data = $null
ABCLeaf ([string]$name, [object]$data) : base ($name)
{
$this.data = $data
}
}