Skip to content

Commit ba8ba05

Browse files
StartAutomatingStartAutomating
authored andcommitted
Adding and Updating READMEs
1 parent b0aa39c commit ba8ba05

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
describe 'New-ScriptBlock' {
3+
it 'New-ScriptBlock Example 1' {
4+
# Without any parameters, this will make an empty script block
5+
New-PipeScript | Should -BeOfType([ScriptBlock])
6+
}
7+
it 'New-ScriptBlock Example 2' {
8+
# We can use -AutoParameter to automatically populate parameters:
9+
New-PipeScript -ScriptBlock { $x + $y} -AutoParameter
10+
}
11+
it 'New-ScriptBlock Example 3' {
12+
# We can use -AutoParameter and -AutoParameterType to automatically make all parameters a specific type:
13+
New-PipeScript -ScriptBlock { $x, $y } -AutoParameter -AutoParameterType double
14+
}
15+
it 'New-ScriptBlock Example 4' {
16+
# We can provide a -FunctionName to make a function.
17+
# New-PipeScript transpiles the scripts it generates, so this will also declare the function.
18+
New-PipeScript -ScriptBlock { Get-Random -Min 1 -Max 20 } -FunctionName ANumberBetweenOneAndTwenty
19+
ANumberBetweenOneAndTwenty | Should -BeLessThan 21
20+
}
21+
it 'New-ScriptBlock Example 5' {
22+
# We can provide parameters as a dictionary.
23+
New-PipeScript -Parameter @{"foo"=@{
24+
Name = "foo"
25+
Help = 'Foobar'
26+
Attributes = "Mandatory","ValueFromPipelineByPropertyName"
27+
Aliases = "fubar"
28+
Type = "string"
29+
}}
30+
}
31+
it 'New-ScriptBlock Example 6' {
32+
# We can provide parameters from .NET reflection.
33+
# We can provide additional parameter help with -ParameterHelp
34+
New-PipeScript -Parameter ([Net.HttpWebRequest].GetProperties()) -ParameterHelp @{
35+
Accept='
36+
HTTP Accept.
37+
HTTP Accept indicates what content types the web request will accept as a response.
38+
'
39+
}
40+
}
41+
it 'New-ScriptBlock Example 7' {
42+
# If a .NET type has XML Documentation, this can generate parameter help.
43+
New-PipeScript -FunctionName New-TableControl -Parameter (
44+
[Management.Automation.TableControl].GetProperties()
45+
) -Process {
46+
New-Object Management.Automation.TableControl -Property $psBoundParameters
47+
} -Synopsis 'Creates a table control'
48+
Get-Help New-TableControl -Parameter *
49+
}
50+
it 'New-ScriptBlock Example 8' {
51+
$CreatedCommands =
52+
[Management.Automation.TableControl],
53+
[Management.Automation.TableControlColumnHeader],
54+
[Management.Automation.TableControlRow],
55+
[Management.Automation.TableControlColumn],
56+
[Management.Automation.DisplayEntry] |
57+
New-PipeScript -Noun { $_.Name } -Verb New -Alias {
58+
"Get-$($_.Name)", "Set-$($_.Name)"
59+
} -Synopsis {
60+
"Creates, Changes, or Gets $($_.Name)"
61+
}
62+
63+
New-TableControl -Headers @(
64+
New-TableControlColumnHeader -Label "First" -Alignment Left -Width 10
65+
New-TableControlColumnHeader -Label "Second" -Alignment Center -Width 20
66+
New-TableControlColumnHeader -Label "Third" -Alignment Right -Width 20
67+
) -Rows @(
68+
New-TableControlRow -Columns @(
69+
New-TableControlColumn -DisplayEntry (
70+
New-DisplayEntry First Property
71+
)
72+
New-TableControlColumn -DisplayEntry (
73+
New-DisplayEntry Second Property
74+
)
75+
New-TableControlColumn -DisplayEntry (
76+
New-DisplayEntry Third Property
77+
)
78+
)
79+
)
80+
}
81+
}
82+

0 commit comments

Comments
 (0)