Solved

Powershell script to prompt for input

Posted on 2011-02-16
4
1,054 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 250 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 250 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

Technology Partners: 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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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