Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell script to prompt for input

Posted on 2011-02-16
4
Medium Priority
?
1,067 Views
Last Modified: 2012-05-11
what would I need for  the script to prompt me for a workgroup name.

param(
              [Parameter(Position=0, Mandatory=$true,ParameterSetName="Workgroup")]
              [string]$Workgroup,
              
              [Switch]$AutoReboot
          )
0
Comment
Question by:chshrmc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Dale Harris earned 1000 total points
ID: 34910663
param(
              [Parameter(Position=0, Mandatory=$true,ParameterSetName="Workgroup")]
              [string]$Workgroup,
               
              [Switch]$AutoReboot
          )
if ($Workgroup -eq $null){$Workgroup = read-host "Enter in the workgroup name"}

HTH,

Dale Harris
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 1000 total points
ID: 34911040

me again :)

If you set Mandatory = $True it will never permit a $Null value for $Workgroup, and therefore never prompt.

You'd have to rip out Mandatory as well, and, since you're casting to a string, test for "" instead of $Null :)

Chris
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34911123
So what you're saying Chris, is that I should just leave the answering to you? :)

My thought on the $null was that the variable was never used, but since it's cast in the parameters, it makes sense that past that point, it will need to be "".

Thanks again for the help.

It never ceases to amaze me how much I don't know about Powershell.

Dale
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34911153
Never :) I just like joining in :)

Chris
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question