Solved

Powershell script to prompt for input

Posted on 2011-02-16
4
1,038 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
  • 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 70

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 70

Expert Comment

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

Chris
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now