Sitecore powershell extension: reading the values from the variables when using Read-Variable command

The other day I was using the very handy Sitecore powershell module and I needed to use the”Read-Variable” command and I was trying to figure out how to actually use the values entered by the user when they fill in the form this command creates. So I decided to create this post to help others so they don’t have to spend too much time figuring it out.

So here is the script I had:

$item = Get-Item master:\content\home

$result = Read-Variable -Parameters `
@{ Name = “someText”; Value=”Some Text”; Title=”Single Line Text”; Tooltip=”Tooltip for singleline”; Placeholder=”You see this when text box is empty”},
@{ Name = “item”; Title=”Start Item”; Root=”/sitecore/content/”} `
-Description “This Dialog shows less editors, it doesn’t need tabs as there is less of the edited variables” `
-Title “Initialise various variable types (without tabs)” -Width 500 -Height 480 -OkButtonName “Proceed” -CancelButtonName “Abort”


Breaking down the script:

It is using the Read-Variable command to generate a form with one text box and a droplink, and a confirm and cancel buttons.

The $result variable  would return ‘ok’ or ‘cancel’ depending on the action the user would take. So to read the value from the input ‘someText’ for example all you have to do is use $Variable:someText.  The same goes for other variables.

Hope this saves you some time!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s