Share via

Powershell Function Calling User-Input

Anonymous
2018-04-30T22:06:51+00:00

First off, sorry for the category this is in... I honestly have no idea what category "Powershell help" should go under.

I was messing around with Powershell and trying to learn it (I'm pretty dang new to it, but I'm learning) and my issue comes into play when I try to use two functions, AND check for user input.

Aka:

Function > Call a function

Called function > Check if there's user input, if there is, then just output it. If there isn't user input, then prompt for it.

It works perfectly as expected when I just use the single function, yet when I try to add another leading into it (it's required for my goal), it screws up and goes wrong. 

By the way, I'd be typing these two things, with the expected result after:

Get-Run 

(Expecting a prompt for "Please enter an age.", then that answer outputted after.

Get-Run -Age 4

(Expecting it to save the age of 4, then outputting it after.)

Of course, I could have it do it in the first function, but that won't work for what I want to do. I need all of this in the second section, if at all possible. If not, then oh well.

Clear-Host

Function Get-Age {

Param(

 [Parameter(Mandatory = $true, HelpMessage="Please enter an age.")]

 [ValidateNotNullorEmpty()]

 [int] $Age

 )

$Age 

}

Function Get-Run {

    Param (

)

Get-Age

}

Windows for home | Windows 10 | Internet and connectivity

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2018-05-01T01:40:51+00:00

    Welp, wrong place! That explains why the category was so confusing to me...

    Thanks of course!

    0 comments No comments