Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
The following function is s utility function. It does not want to be made to look like a CmdLet. We don't need to add the parameter statements and we don't want it to be complicated.
function Get-Index {
param(
[psobject[]]$Services
)
Write-Host 'Returned services:'
$Services | ForEach-Object{ Write-Host $_.Index $_.Status $_.Name -ForegroundColor green }
Read-Host "Which service would you like to restart? (0 - $($Services.Count))"
}
It is also bad coding form to use return to exit a function. This should be reserved for special circumstances. PowerShell always returns all output to the pipeline.
Here is a good set of articles on style, formatting, comment usage and basic overall design of a PS script.
The links can help you to acquire a consistent style that is generally acceptable across the industry and will help you to sort through much of the, at time, frustrating behavior of the PowerShell scripting system. It is not anything like any programming language. PowerShell is designed to solve many issues of scripting languages and systems and, without a deep understanding, PS can be an uphill battle. Just learning to do things form "recipes" will not teach you the internals of PS and may cause you to make incorrect assumptions. Unfortunately most blogs, articles and simple tutorials do little to actually teach the internals of PS.
"PowerShell in Action - Second Edition" by Bruce Payette is an excellent baseline for PowerShell.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.