Converting Powershell to automated scripts
We use Powershell for finding details, setting attributes, commands etc etc. For some of the commands, what I'd like to do is have a PS script that I can run and it will prompt me for the variable. An example, using Exchange, is set-mailbox -identity USER -ProhibitSendQuota 2097152 I have read I can script this using the below and it will ask me for the USER value I want to set this command on mailbox = Read-Host "Mailbox: " set-mailbox -identity $mailbox -ProhibitedSendQuota 2097152 So far, so good. But, another common situation is trying to find an object with certain attributes: For example, finding an object: get-object -Attribute1 #1 -Attribute2 #2 -Attribute3 #3 ...you get the idea If I don't want to enter a value for one of these, how can I "skip" this using something similar to the above script. I found that when I am prompted and if I just hit enter, then I am returned an error saying that I have to enter something. Is there anyway in Powershell to say, if user hits "enter" [or any key] then just ignore that? So for example, I could use the following PS script, and if I didn't know the Attribute1, I could just hit Enter and it wouldn't mind not being given a value for it. Hope this makes sense.
April 13th, 2011 12:44pm

Hi Joe, Please post the issue on below queue, you will get more help from there: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads ->Is there anyway in Powershell to say, if user hits "enter" [or any key] then just ignore that? A: Per my known, it is impossible, if kick any key, that would affect the variable value. Regards! Gavin Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
April 19th, 2011 3:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics