Add an Input Box to Your SharePoint 2010 PowerShell Scripts

10/29/2009

PowerShell

For all of you busy SharePointers out there, this may be a helpful addition to your PowerShell scripts. Adding an input box to a script allows it to be reusable instead of only for a certain web app, site collection, or site. Think of it as an interactive way of passing parameters into PowerShell commands. It’s simple and easy, here’s how:

Add to the top of your script:

[void][System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’)

Call the input box and store the results in a variable:

$var_name = [Microsoft.VisualBasic.Interaction]::InputBox(“Input Description”, “Window Title”)

Use the variable where needed in your PowerShell script:

Get-SPLogEvent| ?{$_.level –eq $var_name} | select Category, Message | more

Example:

Voila!

Advertisements
,

Subscribe

Subscribe to our RSS feed and social profiles to receive updates.

No comments yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: