question

Filip-2434 avatar image
0 Votes"
Filip-2434 asked RichMatheisen-8856 answered

Powershell function parameter

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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).


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.