mercredi 8 décembre 2021

Can anybody help in this poweshell script exercises?

I have two scripting tasks, but I got stuck in them. The first task does not work properly because it prints 1 more number and the consecutive numbers are not correct either. Does anyone have any idea what the mistake might be?

Create a script called a.ps1. The script has one parameter: pieces (pieces are positive integers). Prints a number of random numbers when the script is called. The first random number has a minimum of 0 and a maximum of 9. Subsequent random numbers are a minimum of the previous random number and a maximum of 9.

Param (
 [Parameter (Position = 0, mandatory = $ true)]
 
    [int]$pieces
)
 
$first = Get-Random -Minimum 0 -Maximum 9
 
1..$pieces | % {
 
    Write-output $first
   $random = Get-Random -Minimum 0 -Maximum 9
   $first = $first + $random
 
}

In the second task, the first result should be called using a pipeline, but I don't really understand how it works. Can anyone help me?

Create a Powershell script called b.ps1 that can process the results of the script created in the first task through a pipeline and print as many “#” characters as the number contains.

$input | % {
 
 Write-Output "#"*$_
 
 }



Aucun commentaire:

Enregistrer un commentaire