forked from jdhitsolutions/PSFunctionTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamplefunction.ps1
43 lines (36 loc) · 1.3 KB
/
samplefunction.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
#requires -version 4.0
#requires -runasAdministrator
#this is a sample script
Param (
[Parameter(Position = 0, HelpMessage = "How many numbers do you want?")]
[ValidateRange(1, 100)]
[int]$Count = 1
)
DynamicParam {
#this is a sample dynamic parameter
If ($True) {
$paramDictionary = New-Object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
# Defining parameter attributes
$attributeCollection = New-Object -Type System.Collections.ObjectModel.Collection[System.Attribute]
$attributes = New-Object System.Management.Automation.ParameterAttribute
$attributes.ParameterSetName = '__AllParameterSets'
$attributeCollection.Add($attributes)
# Defining the runtime parameter
$dynParam1 = New-Object -Type System.Management.Automation.RuntimeDefinedParameter('Demo', [String], $attributeCollection)
$paramDictionary.Add('Demo', $dynParam1)
return $paramDictionary
} # end if
} #end DynamicParam
Begin {
Write-Host "this is a sample script that doesn't do anything but write a random number" -ForegroundColor Yellow
}
Process {
#get numbers
1..$count | ForEach-Object {
Get-Random -Minimum 1 -Maximum 1000
}
}
End {
Write-Host "Ending script" -ForegroundColor yellow
}
#eof