Tuesday, August 30, 2016

Googler Shumin Zhai awarded with the ACM UIST Lasting Impact Award



Recently, at the 27th ACM User Interface Software and Technology Symposium (UIST’14), Google Senior Research Scientist Shumin Zhai and University of Cambridge Lecturer Per Ola Kristensson received the 2014 Lasting Impact Award for their seminal paper SHARK2: a large vocabulary shorthand writing system for pen-based computers. Most simply put, this is one of those rare works that is responsible for fundamental and lasting advances in the industry, and is the basis for the rapidly growing number of keyboards that use gesture typing, including products such as ShapeWriter, Swype, SwiftKey, SlideIT, TouchPal, and Google Keyboard.

First presented 10 years ago at UIST’04, Shumin and Per Ola’s paper is a pioneering work on word-gesture keyboard interaction that described the architecture, algorithms and interfaces of a high-capacity multi-channel gesture recognition system-SHARK2. SHARK2 increased recognition accuracy and relaxed precision requirements by using the shape and location of gestures in addition to context based language models. In doing so, Shumin and Per Ola delivered a paradigm of touch screen gesture typing as an efficient method for text entry that has continued to drive the development of mobile text entry across the industry.
"Awarded for its scientific contribution of algorithms, insights, and user interface considerations essential to the practical realization of large-vocabulary shape-writing systems for graphical keyboards, laying the groundwork for new research, industrial applications, and widespread user benefit."
Prior to joining Google in 2011, Shumin worked at the IBM Almaden Research Center for 15 years, where he originated and led the SHARK project, further developing and refining it to include a low latency recognition engine that introduced the ability to accurately recognize a large vocabulary of words based upon the patterns (sokgraphs) drawn on a touchscreen device. SHARK and SHARK2 subsequently continued further development as ShapeWriter. During his tenure at IBM, Shumin additionally pursued a wide variety of HCI research areas including, but not limited to, studying the ease and efficiency of HCI interfaces, camera phone based motion sensing, and cross-device user experience.

At Google, Shumin has continued to inspire the Human-Computer Interaction research community, publishing prolifically and leading a group that incorporates HCI research, machine learning, statistical language modeling and mobile computing to advance the state of the art of text input for smart touchscreen keyboards. Building on his earlier work with SHARK/ShapeWriter, Gesture Typing is just one of the innovations that make things like typing messages on mobile device easier for hundreds of millions of people each day, and remains one of the most prominent features on Android keyboards.

Shumin has been highly active in academia during his career, as both visiting professor and lecturer at world-class universities, and is currently the Editor-in-Chief of ACM Transactions on Computer- Interaction, a Fellow of the ACM and a Member of the CHI Academy. We’re proud to congratulate Shumin and Per Ola on receiving one of the most prestigious honors in the Human-Computer Interaction (HCI) research community, and look forward to their future contributions.
Read More..

Updated trick for enabling Folder option

Many times Windows users face a common problem. The “Folder Options” in “Tools” menu is not visible. Even It can’t be accessed from Control Panel. Also “Registry Editor” is disabled.
Follow the simple steps mentioned in this tutorial and your problem will be solved:

1. If Folder Options is disabled but Registry Editor is still working in your system, then you can enable Folder Options by editing Windows Registry.
Type regedit in RUN dialog box and press Enter.
it’ll open Registry Editor, now go to following keys:
HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrent VersionPoliciesExplorerHKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrent VersionPoliciesExplorer
In right-side pane, check whether a DWORD value named NoFolderOptions exists or not? If it exists, delete it.

2. If you are not familiar with editing the registry, then you can simply download following file, extract it and then run the .REG file:
Folder_option.zip

................................................................................................................
If u cant run regedit ....
Seems like your system is infected with a virus. Pls follow following link:
http://www.askvg.com/is-your-system-infected-with-a-virus-spyware-adware-trojan/

..................................................................................................................
Some ppl find that "show hidden files and folders" option ll not b enabled..
though enabled they cant c the hidden folders...
for that dont worry
--open RUN
--type regedit
--HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrent VersionExplorerAdvanced
And in right-side pane, change value of “Hidden” to 1 and refresh My Computer window and you’ll be able to see hidden files again
Read More..

PowerShell v2 Function Remove FileSecurely Requires sDelete

To help deal with some requirements for an automation project we needed to come up with a way to securely (that means fully) remote data from the system.  We used to use Heidis Eraser, but, this program has proven to be ineffective according to auditors.  So, the Sysinternals sDelete utility was our next option.  I basically wrote the following function to remove files by wrapping sDelete to ensure the data was cleaned up.  From what I can tell sDelete simply overwrites the file space with random data, but, I could be wrong.  sDelete just ensures the actual space, not just the pointers to the used space, is overwritten.  This script assumes the sDelete.exe is located in C:Program FilesSysinternals directory, but, that can be overridden in the script, or, you can simply add the folder path to the file to your environmental variables.
function Remove-FileSecurely {

<#
.AUTHOR
Will Steele

.NOTES
Current version of sdelete has the following help:

SDelete - Secure Delete v1.51
Copyright (C) 1999-2005 Mark Russinovich
Sysinternals - www.sysinternals.com <http://www.sysinternals.com>

usage: C:program filessysinternalssdelete.exe [-p passes] [-s] [-q] <file or directory>
C:program filessysinternalssdelete.exe [-p passes] [-z|-c] [drive letter]
-c Zero free space (good for virtual disk optimization)
-p passes Specifies number of overwrite passes (default is 1)
-q Dont print errors (Quiet)
-s Recurse subdirectories
-z Clean free space

.LINKS
sDelete - http://technet.microsoft.com/en-us/sysinternals/bb897443

.EXAMPLE
md C: est
1..100 | % { dir > C: est$_.txt }
Get-ChildItem C: est*.txt | `
% { Remove-FileSecurely -Name $_ -Passes 10 -LogFormat "HH:mm:ss" -Verbose }
#>

[CmdletBinding()]
param(
[Parameter(
Mandatory = $false,
ValueFromPipeline = $true
)]
[String[]]
$Name,

[Parameter(
Mandatory = $false
)]
[ValidateScript({Test-Path $_})]
$sdeletePath = "C:Program FilesSysinternalssdelete.exe",

[Parameter(
Mandatory = $false
)]
[ValidateScript({$_ -ge 0})]
[Int]
$Passes = 1,

[Parameter(
Mandatory = $false
)]
$LogFormat = "yyyy-MM-dd HH:mm:ss"
)

function Write-TimeStamp
{
Get-Date -Format $LogFormat
}

foreach($item in $name)
{
if(Test-Path -Path $item)
{
# Test to see if item is a directory
if($item.PSIsContainer)
{
Write-Verbose "$(Write-TimeStamp): $item is a directory. Skipping."
}

# Assumes item is a file
else
{
. $sdeletePath -p $Passes $item | Out-NullTo
if(Test-Path $item)
{
Write-Verbose "$(Write-TimeStamp): $item was not deleted."
}
else
{
Write-Verbose "$(Write-TimeStamp): $item was deleted."
}
}
}
}
}
Read More..

Why Watson and Siri Are Not Real AI

A recent article from Popular Mechanics 
raises the common argument that what people call AI actually isnt AI. This argument is based on John Searles Chinese Room thought experiment in which he clearly demonstrates that computers just manipulate symbols. They do not, cannot, ane never will understand what those symbols mean. However, Alan Turing, the father of AI, never claimed that machines would understand. His test for machine intelligence, now called the Turing Test, he originally called "the imitation game." He envisaged that computers would "imitate" intelligence not be intelligent in the sense that we are. Read the Popuar Mechanics article but keep this in mind - its ok for computers to imitate intelligence using different techiques to people just as its ok for planes to fly without flapping their wings like birds.




from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

via Personal Recipe 895909

Read More..

Monday, August 29, 2016

Using the Google Voice C API

First of all, this obviously isnt an official Google API. I wrote it because I wanted one in C++ and couldnt find one that worked.

That being said, the code is on github here (in the TextCommand folder) and is available under GPLv3 for anyone to use.
I know this could (maybe even should) have its own github project but since I use it for my home automation projects, its included in the PiAUISuite. That being said, the current gvapi binary is also compiled for the Pi. So you will need to run make gvapi if you want to use it on any other linux machine.

To include the C++ code in your own project, you just need to include gvoice.h in your file and then you should be able to access the GoogleVoice class. An excellent example to look at is gvapi.cpp since it shows how to interact with it. You should need only to call Init and Login, then you should be able to do any of the Google voice functions.

If you only to use gtextcommand to send commands to your pi, see here. If you want to send or check SMS without having to include the source in your code/project, just use the gvapi program. It can get contacts, send, receive, and delete SMS. It also comes in with built in spoof protection (this is included in GoogleVoice::CheckSMS).

Heres a quick video demo as an example of the kinds of things you can do with gvapi


Using the gvapi program is fairly simple and its man page is below:


gvapi


gvapi - Use of Google voice API in order to send and receive SMS  

SYNOPSIS

gvapi [OPTIONS]...  

DESCRIPTION

gvapi was compiled for use with home automation on the Raspberry Pi but will work on any linux system with an internet connection. It uses curl and boost regex in order to login and stores the cookie in /dev/shm. It only logs in once every 24 hours to save time. It supports a multitude of different options and parameters. For help/comments/questions, feel free to e-mail me at help@stevenhickson.com. I answer sporadically but do eventually respond.
 

OPTIONS

-?
Same as -h
-c
Checks your incoming text messages to see if you have anything unread. It will mark it whatever it outputs as read unless you also use the -r flag. If you include a number with the -n flag, you can specify it to only check messages received from that number. You can also use the -k flag to specify that the message must start with a certain keyword.
-d
Sets debug mode on. You can also specify debug mode from 1 - 3, where 3 is the most verbose.
Ex: gvapi -c -d2
-h
Asks for some quick general use help for gvapi.
-i
Outputs the contacts of your google voice account in the form name==number
-k KEYWORD
Sets a keyword that has to be in the beginning of the text message for it to be returned. This is useful as a password for parsing only certain messages.
-m MESSAGE
Sends the message you specify. This should be in quotes if it contains special characters or a space. The number also has to be specified otherwise it wont have a message to send
Ex: gvapi -n +15551234 -m Hello
-n NUMBER
Can be used with the -c flag to check messages from a certain number or the -m flag to send a message. Can be in a format without the country code, with just the country code, or with a plus sign and the country code. If the formost, it interprets it as a US number.
Ex: gvapi -n 5551234 -c
-p PASSWORD
Can be used with the -u flag to log in manually. If not specified, the program uses the default username and password specified in ~/.gv
-r
Receives and deletes SMS messges. Can be used with the -c flag or without. It is the same as the -c flag but instead of just marking the messages as read. It deletes them.
-u USERNAME
Can be used with the -p flag to log in manually. See the -p flag for more details. Cannot be used without the -p flag.
-v
Outputs version and creater information

AUTHOR

Steven Hickson (help@stevenhickson.com)  

BUGS

No known bugs. To report bugs, send a clear description to help@stevenhickson.comSince this program is fairly crude, user typos could cause crashes/failed responses. Please read the man page thoroughly before submitting a bug.  

COPYRIGHT

Copyright © 2013 Steven Hickson. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it as long as you give credit to the author and include this license. There is NO WARRANTY, to the extent permitted by law.  

HISTORY

This is the second major version of this program  

SEE ALSO

http://stevenhickson.blogspot.com/

Consider donating to further my tinkering.


Places you can find me
Read More..

PowerShell v2 Function Hide Folder

While working on a project I came up with a quick need to hide a folder, so, I wrote this canned function:
function Hide-Folder
{
      param(
            $foldername
      )
     
      if(Test-Path $foldername)
      {
            $(Get-Item $foldername).Attributes = Hidden
      }
      else
      {
            Write-Error "The folder ($($foldername)) was not found."
      }
}
The source of the .Attributes trick was:
 Get or set filedirectory attributes using Powershell
Read More..

Sunday, August 28, 2016

The Tears of Donald Knuth

Happy New Year. I hope you all had a good festive season. Ill start this years blog with a link to a fascinating article on the history of computer science by Thomas Haigh in the Communications of the ACM titled "The Tears of Donald Knuth" brought to my attention by colleague Bob Doran. This interesting piece puts forward a very cogent argument as to why there is so little written about the history of computer science - basically you cant make a career at it; computer science histories are therefore mostly written by CS academics as a hobby in their spare time, not by trained historians. You can read the full article here.

from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

Read More..

This day in history the first tweet

On March 21 2006 Jack Dorsey sent the very first tweet. Like many tweets not especially informative and presumable Jack didnt have many, if any, followers. Twitter was opened to the public that July and had its first major success at the South by Southwest (SXSW) conference in 2007, shortly after it had been made into a company. And the rest< as they say, is history. You can follow me and this blog @driwatson

from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

via Personal Recipe 895909

Read More..

B Sc IT Mumbai subjects with electives

Hi! Those who have just passed std 12th from Science Stream and wondering what next. B.Sc IT (Bachelor of Science in Information Technology) in one of the best option you can go for. In India, Bachelor of Science in Information Technology is a 3 year course alone with Bachelor of Information Science, this degree is completely different from normal B.Sc.
A candidate for being eligible for admission to the degree course in Information Technology must have passed the H.S.C Examination of the Maharashtra Board of Higher Secondary Education or its equivalent and secured not less than 45% marks in the aggregate.

Below are the subjects offered in this course along with the electives.

Read More..

Saturday, August 27, 2016

PowerShell v3 in a Year Day 8 about Split

I did not discover the Split operator for far too long in my workings with PowerShell. I had used similar things in Javascript, C#, Perl and VBScript, but, didnt know about this one. Man, was I missing the boat. In PowerShell, the general syntax is to place whatever you want to split on the left hand side of the operator, the -split operator in the middle and the delimiter on the right hand side of the operator as below:

"Lastname:FirstName:Address"-split "(:)" 
When you run this it returns five values:

Lastname
:
FirstName
:
Address 
The delimited is a character (or characters) that identify the end of the substring. The default is whitespace, which includes spaces and control characters, such as new line (`n) and tab (`t). Normally, the delimiter is omitted from the result set. To preserve part (or all) of it, enclose the part you want to retain in parentheses.

For example, here is an instance where the delimiter is omitted:
test1234test1234test123 -split test
Note that I am using a multi-character delimiter. It is good to be aware that you are not limited to single-character delimiters. This outputs the following:

1234
1234
123
Now, here is an example of where you retain the delimiter, test, by placing it in quotes:
 test1234test1234test123 -split (test)
and its output:

test
1234
test
1234
test
123
 NOTE: When providing an initial definition for -split I said, "In PowerShell, the general syntax is to place whatever you want to split on the left hand side of the operator, the -split operator in the middle and the delimiter on the right hand side of the operator". What I want to emphasize here is the condition in general. The operator has a second use where you can specify the maximum number of substrings after the delimiter.

For example, taking our previous example, let us say we only wanted three substrings for a space-delimited list of letters, a b c d e f, how would we do that in PowerShell? Like this,
a b c d e f -split ,3
When you run this in PowerShell it returns this:
a
b
c de f
What is happening is PowerShell tokenizes the string, and, pops 1 (a), 2(b) and 3 (c d e f) character groups for the result. This is useful when you need to have a fixed number of results but cant control the input. Note that values of 0 or negative integers will return the full, original substring.

One interesting use of the right hand side of the operator is to pass to it script blocks. For example, taking one straight from the help, we want to split if the character is an e or a p.
$c = "Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune"
$c -split{$_ -eq"e" -or$_ -eq"p"}
When it is run, it returns the following:
M
rcury,V
nus,Earth,Mars,Ju
it
r,Saturn,Uranus,N

tun
This can be very helpful if you have very specific conditions you need to meet, and/or criteria to match against. Additionally, you can perform dynamic analysis, i.e., calculations, with scriptblocks.

Another powerful aspect of the -split operator is its option set. At present there are two sets, each with a few suboptions, to pay attention to. I have included a list of these below.

  1. SimpleMatch: Use simple string comparison when evaluating the delimiter. Cannot be used with RegexMatch.
    1. IgnoreCase: Forces case-insensitive matching, even if the -cSplit operator is specified.
  2. RegexMatch: Use regular expression matching to evaluate the delimiter. This is the default behavior. Cannot be used with SimpleMatch.
    1. IgnoreCase: Forces case-insensitive matching, even if the -cSplit operator is specified.
    2. CultureInvariant: Ignores cultural differences in language when evaluting the delimiter. Valid only with RegexMatch.
    3. IgnorePatternWhitespace: Ignores unescaped whitespace and comments marked with the number sign (#). Valid only with RegexMatch.
    4. ExplicitCapture: Ignores non-named match groups so that only explicit capture groups are returned in the result list. Valid only with RegexMatch.
    5. SingleLine: Singleline mode recognizes only the start and end of strings. Valid only with RegexMatch. Singleline is the default.
    6. MultiLine: Multiline mode recognizes the start and end of lines and strings. Valid only with RegexMatch. Singleline is the default.
These rules are helpful when dealing with edge cases that require a little extra TLC to properly manage. The syntax for these is to include a third comma separate value after the max substring indicator. For example, the help examples provide a here string for which we use a regex with the multiline option. The here-string is:
$a = @
1The first line.
2The second line.
3The third of three lines.
@
The syntax for handling this with -Split looks like this:
 $a -split"^d",0, "multiline"
All we are trying to do with this regex is to return all substrings (with a maxsubstrings value of 0) and an option of "multiline". When it is run, it returns this:

The firstline.

The secondline.

The thirdof threelines.
The fourth key point about using -Split involves recognizing a difference between unary and binary splitting. Unary splitting, where there is no left hand side to the statement, has a higher precedence order than a binary split operator, where there are both left and right hand sides to a statement. To explain this, let us look at this example. For example, if we evaluate the following statement,
-split "1 2", "a b"
It returns this
1
2
 a b
Since my first exposure to -Split was the binary operator, this was a little confusing to me first. It seemed, in my initial understanding (binary operator only) you had to have both a Left Hand Side (LHS) and a Right Hand Side (RHS) to form a complete statement. For binary operation, this is true, but, not for unary operation.

As noted earlier, when PowerShell encounters a -Split operator, the first thing it will do is try to evaluate it as a unary operator where only a RHS is expected. If that fails, it will then fall through to the second condition, binary operation, and, PowerShell will then attempt to evaluation the statement as having both a LHS and a RHS. It is important to keep this in mind if you ever run into odd behavior with the -Split operator. Glance at your LHS and RHS to be sure they make sense and no lexical errors could be forcing the wrong mode (unary instead of binary or binary instead of unary) of operator to be evaluated.

When working with binary operators in particular, you can force a set of strings to be evaluated by wrapping them in parentheses on the RHS, such as,
(1 2, 3 4) -split ,
which evaluates to
1 2
3
Here are some other results. Splitting on nothing, (1 2, 3 4) -split , gives you,

1

2


How to display codes in blogger post

Display code in blogger postCode without border.

Display code in blogger postCode with border.

Have you ever tried to display codes in blogger. Many blog posts display codes. I always wonder how is this code displayed. After deep search with Google, I found the secret. In this post, i will share with you, how to display codes as it is in any of your post.

  • First of all copy your code and encode your code. Click here to do this.
  • After you click on encode button your code will be encoded. Copy the code.
  • Paste it in your post. Thats it.
  • If you want to add a border or put the code inside a box, Place the encoded code inside <fieldset style="border: 1px dotted ;>------your code------</fieldset> tag

Lets try one:
  • Go to Blogger >> Posting >> Create.
  • Copy the code : <data:blog.pageTitle/> </title> </b:if> or <data:blog.pageTitle/> </title>
  • Encode it.
  • To display code inside a box, paste the code inside this tag. <fieldset style="border: 1px dotted ;>------your code------</fieldset>
  • To display without box, simply paste it anywhere you want.
  • Try Clicking on Preview.

Happy Blogging.
Read More..

How to Use Multiple Gtalk

Read More..

Google Research Awards Winter 2014



We have just completed another round of the Google Research Awards, our biannual open call for proposals on computer science-related topics including robotics, natural language processing, systems, policy, and mobile. Our grants cover tuition for a graduate student and provide both faculty and students the opportunity to work directly with Google researchers and engineers.

This round we received 691 proposals, an increase of 19% over last round, covering 46 countries on 6 continents. After expert reviews and committee discussions, we decided to fund 115 projects. The subject areas that received the highest level of support were human-computer interaction, systems, and machine learning, with 25% of the funding awarded to universities outside the U.S.

We set a new record this round with over 2000 reviews done by 650 reviewers. Each proposal is reviewed by internal committees who provide feedback on merit and relevance. In many cases, the committees include some of the foremost experts in the world. All committee members are volunteers who spend a significant amount of time making the Research Award program happen twice a year.

Congratulations to the well-deserving recipients of this round’s awards. If you are interested in applying for the next round (deadline is April 15), please visit our website for more information.
Read More..

Watson in your pocket

No relation to me -  IBMs Watson, the cognitive computer that can be an expert in any subject, is moving to the cloud, and will soon be accessible via smartphone app An article in the New Scientist says that Watson is moving into the cloud and will soon be accessible via smartphone. If you could quiz Watson, IBMs all-knowing supercomputer, from an app on your phone, what would you ask it? In February this year IBM invited potential app developers to pitch them their ideas. IBM whittled 100s of ideas down to 3 Grand Finalists. You can get more information on them here.

from The Universal Machine http://universal-machine.blogspot.com/

IFTTT

Put the internet to work for you.

Turn off or edit this Recipe

Read More..

Friday, August 26, 2016

PPT Presentation on String Handling

PPT Presentation on String Handling

Some important points are listed below

  • String Class
  • StringBuffer Class
  • String Constructors
  • String Class Methods
  • StringBuffer Class Constructors
  • Methods of StringBuffer Class



This article is shared by one of the reader: Tulsi
Download the file here:

  • String Handling.ppt
Read More..

Hidden Programs In Windows XP !

Is it strange to hear , but true that some good programs are hidden in Windows XP !!!

Programs :

1. Private Character Editor :

Used for editing fonts,etc.
** start>>Run
** Now, type eudcedit

2. Dr. Watson :

This an inbuilt windows repairing software !
** start>>Run
** Now, type drwtsn32

3. Media Player 5.1 :

Even if you upgrade your Media Player, you can still access your old player in case the new one fails !!!
** start>>Run
** Now, type mplay32

4. iExpress :

Used to create SetupsYou can create your own installers !
** start>>Run
** Now, type iexpress
Read More..

Fake Magazine Covers

Here is a question for you…Have you ever wanted to be on the cover of Sports Illustrated? Or any magazine for that matter? Think of the fun you can have with your friends and family to have a magazine cover with your picture on it, printed and framed, hanging on your wall.

Well, I have found this site where you can get Fake Magazine Covers and it will not cost you a single cent. Check it out, this site has more than 100 magazine covers for you to have your picture placed on. Very simple to do, and no I am not going to put my picture on a cover!

All you have to do is go to the site, Fake Magazine Covers, and upload your picture. Simple to do as the uploader is right at the top right. Once you have uploaded your picture, find the magazine cover or magazine covers you want your picture on. Just easy to do and then print your cover for a nice memento and of course to frame.

Do go by this site soon and start having fun, it is as I said free. And do let your family, friends and coworkers know about this site. Heck, then you can all compare your magazine covers with one another and see who has the best, and the worst.

  • http://covervision.com

--------------------------------------------------------------------------------
Read More..

PowerShell v2 ParameterSets for Dummies

I am a big fan of PowerShell functions. Particularly the ones that are more complex, and, with a few exceptions, could easily pass as full-blown cmdlets. In spite of this, I still havent gotten my head around one of the features, ParameterSets, which I think are very powerful. I threw out a Tweet to see if anyone could throw me a line, and, a few folks gave me links. (Thanks Ed, Trevor and Jon). After reading through Eds link:
Use Parameter Sets to Simplify PowerShell Commands
I decided Id start from scratch with some basics and build up from there. So, I started with this:
function Test-ParameterSet
{
      param(
            $one,
            [Parameter(
                  ParameterSetName = Two
            )]
            [Switch]
            $Two,
            [Parameter(
                  ParameterSetName = Three
            )]
            [Switch]
            $Three
      )
     
      $one
}
When I run this, I approach it several different way to see what breaks, and, what works:
Test-ParameterSet -One 1
produces:
Test-ParameterSet : Parameter set cannot be resolved using the specified named parameters.

At C:UserswsteeleAppDataLocalTemp562a6843-2adf-4bba-ad3e-f22052430aca.ps1:20 char:18
+ Test-ParameterSet <<<<  -One 1 -Two -three
    + CategoryInfo          : InvalidArgument: (:) [Test-ParameterSet], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Test-ParameterSet
These two work:
Test-ParameterSet -One 1 –Two
Test-ParameterSet -One 1 –Three
But, this doesnt:
Test-ParameterSet –One1 –Two –Three
And, neither does this:
Test-ParameterSet –Two –Three
So, these are some simple, basic tests. Taking it up one step I add a parameter, $Four, that depends on $three by being a member of the Three parameter set.
function Test-ParameterSet
{
      param(
            $one,
            [Parameter(
                  ParameterSetName = Two
            )]
            [String]
            $Two,
            [Parameter(
                  ParameterSetName = Three
            )]
            [String]
            $Three,
            [Parameter(
                  ParameterSetName = Three
            )]
            [String]
            $Four
      )
     
      if($one) {
            $one
      }
      if($two) {
            $two
      }
      if($three) {
            $three
      }
      if($Four) {
            $four
      }
}
The same rules as above apply:

  • any parameter not a member of a specific parameter set can be used so long as one member of the parameter set parameters is called
  • unless a parameter in a parameterset is configured with Mandatory = $true you can call other parameterset members without calling the given parameter
Point 1any parameter not a member of a specific parameter set can be used so long as one member of the parameter set parameters is called
Test-ParameterSet -one 1 -Four 4
returns 1 and 4. Note that -Three is neither used nor required.

Point 2unless a parameter in a parameterset is configured with Mandatory = $true you can call other parameterset members without calling the given parameter
By adding Mandatory = $true to the [Parameter()] definition for three, the above command prompts you for -Three, but, once executed, runs fine.
For me the, big lesson here is that, if you  add parameter sets, remember, you must call at least one member of one parameter set or else the function/script will not run. I need to explore how this works with dynamic parameters, but, for now, I can at least start using parameter sets more effectively in my scripts with an idea of how they basically work.

As you explore how to work with this, I found the Get-Help cmdlet really useful as it paints a picture of what your parameter sets really are in usage, not just as a construct in your head. Using my last incarnation of the above function,
function Test-ParameterSet
{
      param(
            $one,
            [Parameter(
                  ParameterSetName = Two
            )]
            [String]
            $Two,
            [Parameter(
                  Mandatory = $true,
                  ParameterSetName = Three
            )]
            [String]
            $Three,
            [Parameter(
                  ParameterSetName = Three
            )]
            [String]
            $Four
      )
     
      if($one) {
            $one
      }
      if($two) {
            $two
      }
      if($three) {
            $three
      }
      if($Four) {
            $four
      }
}
I get the following when I run Get-Help:
Test-ParameterSet [-one ] [-Two ] [-Verbose] [-Debug] [-ErrorAction ] [-WarningAction ] [-ErrorVariable ] [-WarningVariable ] [-OutVariable ] [-OutBuffer ]
Test-ParameterSet [-one ] -Three [-Four ] [-Verbose] [-Debug] [-ErrorAction ] [-WarningAction ] [-ErrorVariable ] [-WarningVariable ] [-OutVariable ] [-OutBuffer ]
Notice that the -Three parameter in the second collection does not have brackets around it. This indicates that parameter is Mandatory. Compare against the Two parameter set parameter collection in which both parameters (-One and -Two) are bracketed, i.e., not mandatory. I highlighted the function specific parameters (i.e., non-common parameters) to emphasize the breakdown of the parameter sets. Also emphasized is the -Three parameter in the Three parameter set to demonstrate the difference between Mandatory = $true and Mandatory = $false (the default).
< Read More..
 
Copyright 2009 Information Blog
Powered By Blogger