Skip to content

Commit 5f7b9ea

Browse files
authored
Update script :neckbeard:
1 parent 4612503 commit 5f7b9ea

1 file changed

Lines changed: 55 additions & 37 deletions

File tree

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
# -------------------------------------------------------------------------------
22
# Author: Blake Drumm (blakedrumm@microsoft.com)
33
# Date Created: November 1st, 2023
4-
# Edit line 7 if you want to change the module or command to get information on.
4+
# Script to get details of the '-SCOMAleAddrtResolutionState' command in the 'OperationsManager' module.
5+
# Edit line 8 if you want to change the module or command to get information on.
56
# -------------------------------------------------------------------------------
67
# Get details of commands in a specific module
78
$commandDetailsList = foreach ($function in (Get-Command -Module OperationsManager)) {
89

9-
# Determine the input types based on parameters accepting pipeline input
10-
$inputTypes = $function.Parameters.Values | Where-Object {
10+
# Identify mandatory parameters that accept pipeline input
11+
$mandatoryPipelineInputParams = $function.Parameters.Values | Where-Object {
1112
$_.Attributes | Where-Object {
12-
$_ -is [System.Management.Automation.ParameterAttribute] -and ($_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName)
13+
$_ -is [System.Management.Automation.ParameterAttribute] -and
14+
$_.Mandatory -and
15+
($_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName)
1316
}
14-
} | ForEach-Object { $_.ParameterType.FullName } | Sort-Object -Unique
15-
16-
# Create a custom object for each function
17-
$functionDetails = [PSCustomObject]@{
18-
Name = $function.Name
19-
InputType = if ($inputTypes) { $inputTypes } else { 'None' }
20-
OutputType = if ($function.OutputType) { $function.OutputType.Name } else { 'None' }
21-
Parameters = @()
2217
}
23-
24-
# Get parameter details
18+
19+
# Initialize an array to hold formatted parameter details strings
20+
$paramDetailsList = @()
21+
22+
# Get parameter details and format them into strings
2523
foreach ($parameterName in $function.Parameters.Keys) {
2624
$parameter = $function.Parameters[$parameterName]
27-
25+
2826
# Retrieve aliases for the parameter
2927
$aliasAttribute = $parameter.Attributes | Where-Object { $_ -is [System.Management.Automation.AliasAttribute] }
3028
$aliases = if ($aliasAttribute -and $aliasAttribute.AliasNames) {
@@ -49,11 +47,16 @@ $commandDetailsList = foreach ($function in (Get-Command -Module OperationsManag
4947
$pipelineInput = $parameter.Attributes | Where-Object {
5048
$_ -is [System.Management.Automation.ParameterAttribute] -and ($_.ValueFromPipeline -or $_.ValueFromPipelineByPropertyName)
5149
}
52-
$pipelineInputType = 'None'
53-
if ($pipelineInput.ValueFromPipeline) {
54-
$pipelineInputType = 'ByValue'
55-
} elseif ($pipelineInput.ValueFromPipelineByPropertyName) {
56-
$pipelineInputType = 'ByPropertyName'
50+
$pipelineInputType = if ($pipelineInput) {
51+
if ($pipelineInput.ValueFromPipeline) {
52+
'ByValue'
53+
} elseif ($pipelineInput.ValueFromPipelineByPropertyName) {
54+
'ByPropertyName'
55+
} else {
56+
'None'
57+
}
58+
} else {
59+
'None'
5760
}
5861

5962
# Check if the parameter has a specific position
@@ -62,25 +65,40 @@ $commandDetailsList = foreach ($function in (Get-Command -Module OperationsManag
6265
}
6366
$position = if ($positionAttribute) { $positionAttribute.Position } else { 'Named' }
6467

65-
# Create a custom object for each parameter
66-
$paramDetails = [PSCustomObject]@{
67-
Name = $parameterName
68-
Type = $parameter.ParameterType.FullName
69-
DefaultValue = $defaultValue
70-
Required = $parameter.Attributes.Mandatory
71-
AcceptsWildcardChars = $wildcardSupport -ne $null
72-
AcceptsPipelineInput = $pipelineInputType
73-
Position = $position
74-
Aliases = $aliases
75-
}
68+
# Format each parameter detail into a string
69+
$paramDetailString = "Name: $($parameterName)`n" +
70+
"Type: $($parameter.ParameterType.FullName)`n" +
71+
"DefaultValue: $($defaultValue)`n" +
72+
"Required: $($parameter.Attributes.Mandatory)`n" +
73+
"AcceptsWildcardChars: $($wildcardSupport -ne $null)`n" +
74+
"AcceptsPipelineInput: $($pipelineInputType)`n" +
75+
"Position: $($position)`n" +
76+
"Aliases: $($aliases)"
7677

77-
# Add the parameter details object to the function details
78-
$functionDetails.Parameters += $paramDetails
78+
# Add the formatted string to the list
79+
$paramDetailsList += $paramDetailString
7980
}
8081

81-
# Return the custom object for the function
82-
$functionDetails
82+
# Generate example for piping object with mandatory parameters
83+
$examplePiping = if ($mandatoryPipelineInputParams) {
84+
$exampleObjectProps = $mandatoryPipelineInputParams | ForEach-Object {
85+
"$($_.Name) = <" + $_.ParameterType.Name + ">"
86+
}
87+
"[PSCustomObject]@{" + ($exampleObjectProps -join "; ") + "} | $($function.Name)"
88+
} else {
89+
"No mandatory pipeline input parameters available"
90+
}
91+
92+
# Create a custom object for the function with all collected details
93+
[PSCustomObject]@{
94+
Name = $function.Name
95+
InputType = if ($mandatoryPipelineInputParams) { $mandatoryPipelineInputParams.ParameterType.FullName | Sort-Object -Unique } else { 'None' }
96+
OutputType = if ($function.OutputType) { $function.OutputType.Name } else { 'None' }
97+
Parameters = $paramDetailsList -join "`n`n"
98+
PipelineInputParams = $mandatoryPipelineInputParams.Name -join ', '
99+
ExampleUsage = $examplePiping
100+
}
83101
}
84102

85-
# Output the details or store them in a variable for further processing
86-
$commandDetailsList
103+
# Output the details in a structured format
104+
$commandDetailsList | Format-List

0 commit comments

Comments
 (0)