Powershell function parameter

Filip 831 Reputation points
2021-03-25T12:17:58.957+00:00

Hello everyone.
I have here powershell code from internet. Can somebody explain me what maens the part where is the "param" and these vales. Can i somehow modifie it or do something with this?
If you have some good documentation don't wait and send me it i will read.
Thank for answare.

Function Get-Weather {
[Alias('Wttr')]
[Cmdletbinding()]
Param(
[Parameter(
Mandatory = $true,
HelpMessage = 'Enter name of the City to get weather report',
ValueFromPipeline = $true,
Position = 0
)]
[ValidateNotNullOrEmpty()]
[string[]] $City,
[switch] $Tomorrow,
[switch] $DayAfterTomorrow
)

Process
{
Foreach($Item in $City){
try {
# Check Operating System Version
If((Get-WmiObject win32_operatingsystem).caption -like "Windows 10") {
$Weather = $(Invoke-WebRequest "http://wttr.in/$City" –UserAgent curl).content -split "n" } else { $Weather = (Invoke-WebRequest "http://wttr.in/$City").ParsedHtml.body.outerText -split "n"
}
If($Weather)
{
$Weather[0..16]
If($Tomorrow){ $Weather[17..26] }
If($DayAfterTomorrow){ $Weather[27..36] }
}
}
catch {
$_.exception.Message
}
}
}
}

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-03-25T14:38:22.203+00:00

    You'll find all you need to know in the PowerShell help:

    help about_parameters
    help about_functions_advanced_parameters

    You'll find those topics by searching for them on the web, too.

    You can also find a very informative book in PDF format (it's free) here: Windows-PowerShell-4
    Read at least the 1st half of the book. The "In-depth" chapters are good, too (the 2nd half of the book).

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.