# read-host

**URL:** <https://forums.powershell.org/t/read-host/9929>\
**Category:** PowerShell Help\
**Created:** [January 2, 2018, 11:37am UTC](https://forums.powershell.org/t/read-host/9929 "2018-01-02T11:37:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonp](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@leonp](https://forums.powershell.org/u/leonp)\
**Post date:** [January 2, 2018, 11:37am UTC](https://forums.powershell.org/t/read-host/9929/1 "2018-01-02T11:37:10Z")

</div>

Hello all,

This is an easy one and just me being stupid, i am running the below but for some reason now i have used mandatory=$true it now longer adds the message section.

This is the parameter i am using,

[CmdletBinding()]  
param(  
[Parameter(Mandatory=$True)]  
[String] $UpdateDay = (Read-Host -Prompt ‘Enter Value for the Day Windows updates will install. Sunday = 1, Monday = 2,  
Tuesday =3, Wednesday = 4, Thursday = 5, Friday = 6, Saturday = 7’),  
[string] $UpdateTime = (Read-Host -Prompt ‘Enter update time. Values use the numner to represent hour on a 24 Hour clock,  
i.e (03:00 =3) (18:00 = 18)’)  
)

And below is the output i get rather than including the output to user,

cmdlet at command pipeline position 1  
Supply values for the following parameters:  
UpdateDay:

Thanks in advance Leon.

---

<div class="post-metadata">

**Author:** ![jacorbello](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jacorbello](https://forums.powershell.org/u/jacorbello)\
**Post date:** [January 2, 2018, 11:59am UTC](https://forums.powershell.org/t/read-host/9929/2 "2018-01-02T11:59:14Z")

</div>

Use “HelpMessage” when declaring your parameters:

```
function test {
    [CmdletBinding()]
    param(
    [Parameter( Mandatory=$True,
                HelpMessage="Enter Value for the day Windows updates will install. Sunday = 1, Monday = 2, Tuesday =3, Wednesday = 4, Thursday = 5, Friday = 6, Saturday = 7"
                )][String] $UpdateDay,
    [Parameter( Mandatory=$True,
                HelpMessage="Enter update time. Values use the number to represent hour on a 24 Hour clock, i.e (03:00 =3) (18:00 = 18)"
                )][string] $UpdateTime
    )
}
```

I’d also mention that the way you’re asking users to enter data is inefficient and will most likely end up in errors. For the days, I’d use a set so they just select the day that they want. You can convert that to numerical form later in the script.  
[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about\_functions\_advanced\_parameters?view=powershell-5.1#validateset-attribute](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-5.1#validateset-attribute)  
The hour representation is fine, I suppose.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [January 2, 2018, 12:01pm UTC](https://forums.powershell.org/t/read-host/9929/3 "2018-01-02T12:01:58Z")

</div>

Once you specify Mandatory, the command won’t run unless a value is explicitly entered. Default values are ignored - including your Read trick.

---

<div class="post-metadata">

**Author:** ![leonp](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@leonp](https://forums.powershell.org/u/leonp)\
**Post date:** [January 3, 2018, 5:03am UTC](https://forums.powershell.org/t/read-host/9929/4 "2018-01-03T05:03:11Z")

</div>

Hello All,

Thank you for the help, i have changed the script block to include a help message and convert the input to numeric later on. On a separate note how do you add the power-shell box Jeremy used in his post, this will help make my next post more clear?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 3, 2018, 5:43am UTC](https://forums.powershell.org/t/read-host/9929/5 "2018-01-03T05:43:59Z")

</div>

[How to Format Code in the Forums](https://powershell.org/forums/topic/how-to-format-code-in-the-forums/) (That’s the first post on top of the list in this forum!)

---

<div class="post-metadata">

**Author:** ![leonp](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@leonp](https://forums.powershell.org/u/leonp)\
**Post date:** [January 3, 2018, 10:23am UTC](https://forums.powershell.org/t/read-host/9929/6 "2018-01-03T10:23:39Z")

</div>

The Script is now working :). However, the script i was writing was to automate the local group policy settings i generally use on server builds, such as setting WSUS server location. The script was using the Set-ItemProperty commands to edit the regisrty, now that the script runs i have noticed that gpupdate or logon/logoff overwrites the values that i have set, is there a way to stop this or a better way of doing this?

I cannot add these to a domain as they are tailored for each clients needs and most do not want a domain controller. I have googled this but all solutions are generally installing third party software etc, which would take just as much time to do each time as just editing the local GP.

---

<div class="post-metadata">

**Author:** ![jacorbello](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jacorbello](https://forums.powershell.org/u/jacorbello)\
**Post date:** [January 3, 2018, 10:42am UTC](https://forums.powershell.org/t/read-host/9929/7 "2018-01-03T10:42:50Z")

</div>

So these are workgroup computers? i.e. not part of a domain environment?  
If that’s the case, just add that script to startup on the PC’s.

Also, what is the reason for not having domained computers? Just curious on that one.

---

<div class="post-metadata">

**Author:** ![leonp](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@leonp](https://forums.powershell.org/u/leonp)\
**Post date:** [January 3, 2018, 11:19am UTC](https://forums.powershell.org/t/read-host/9929/8 "2018-01-03T11:19:51Z")

</div>

Hello Jeremy,

Thanks for the advice, they are client servers that are bespoke for hosted applications etc. Naturally most clients are not willing to add the cost of a domain controller to manage the 1-2 servers they have with us.

---

<div class="post-metadata">

**Author:** ![jacorbello](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jacorbello](https://forums.powershell.org/u/jacorbello)\
**Post date:** [January 3, 2018, 11:54am UTC](https://forums.powershell.org/t/read-host/9929/9 "2018-01-03T11:54:39Z")

</div>

Ah, makes total sense now. Yeah, a startup script should do the trick. Or you could look into PowerShell DSC. Could give you more granularity and easier to manage in the long run.

[https://docs.microsoft.com/en-us/powershell/dsc/overview](https://docs.microsoft.com/en-us/powershell/dsc/overview)

---

<div class="post-metadata">

**Author:** ![leonp](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@leonp](https://forums.powershell.org/u/leonp)\
**Post date:** [January 4, 2018, 4:39am UTC](https://forums.powershell.org/t/read-host/9929/10 "2018-01-04T04:39:38Z")

</div>

Thanks Jeremy, i will have a look into DSC now 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:36pm UTC](https://forums.powershell.org/t/read-host/9929/11 "2024-05-16T20:36:55Z")

</div>


