?
Solved

Powershell script to prompt for input

Posted on 2011-02-16
4
Medium Priority
?
1,059 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

801 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