Alan's Blog

"Yeah. I wrote a script that will do that."

Menu
  • About My Blog
Menu

Two Column WPF Form to Select Items or Properties

Posted on January 6, 2019September 12, 2020 by Alan

Many of my scripts are written for other people to do Active Directory reporting.  One of my goals in supporting them is to give them as much flexibility in the data returned with the minimum amount of custom coding required.   Convert-ADValues (which I will update soon), outputs friendly dates and expanded information for certificates, groups and the object’s security. I have also published a Windows forms based GUI to select object properties.

This script, Select-ItemsWithListBoxes.ps1, is an WPF advanced function which for selecting items.  I designed the form using the method described in Practical Lessons on WPF Forms and PowerShell.

A simple example of this function presents a list of ASCII characters as items to select, created with this command:

#Get list of characters.
$list = (33..126 | ForEach-Object{[char][byte]$_})
# Note that with a simple list you cannot use the pipeline.
Select-ItemswithListboxes -inputobject $list

The result is form to select a list of the characters.  On “Accept” the items in the right column are returned.

Here we select properties from Get-ADUser, splatting the parameters:

#Get all users with all properties, send to function to select properties. Splatting params
$params = @{
    Filter        = '*'
    properties    = '*'
    SearchScope   = 'Subtree'
}
#Here you can use the pipeline
get-aduser  @params | 
Select-ItemsWithListBoxes -SelectProperties

This presents the properties from the object in the pipeline.  When the user accepts the list, the items in the right column are used to filter the properties of the object in the pipeline.   In this example, the pipeline would contain user objects with the Name, Description and Office Phone properties.

Note the difference in the two examples.  When you use the script to select a list of items, you cannot use the pipeline.  Create the list and set it as the argument for the inputobject variable.

The script has the current version of my Dot Source Reminder for advanced functions. In my experience, new PowerShell users often try to run advanced and find that noting happens when they are loaded.  I add this bit of code at the end of my advanced functions so that when they are executed, you get a notification like this:

You have loaded the advanced function "Select-ItemsWithListBoxes"
	Use "Get-Help" for information and usage, Ex:
	PS C:\> Get-Help Select-ItemsWithListBoxes -detailed

The downside of the notification is that you need to hide it when manually loading the functions.  Here is a generalized AD reporting script which lets the user select any value from AD for reporting:

#Load the scripts.  Redirect output to null to hide the dot source reminder
. "C:\PowerShellScripts\Select-ItemsWithListBoxes.ps1" |out-null
. "C:\PowerShellScripts\Convert-ADValues.ps1" |out-null

$params = @{
    Filter        = '*'
    properties    = '*'
    SearchScope   = 'Subtree'
}

get-aduser  @params | 
Select-ItemsWithListBoxes -SelectProperties | 
Convert-ADValues | 
Export-CSV -Path $env:userprofile\desktop\Example.csv -NoTypeInformation

I first presented this script at the January meeting of the Charlotte Powershell User’s Group. Find (or start) a PowerShell user group. In my experience, it has been a very worthwhile experience.

Script Text

Leave a Reply

You must be logged in to post a comment.

Search

Please Note

All the scripts are saved as .txt files. Newer files have a “View Script” button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use “Save Target As”. Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with version 3 or later.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient.  If you find a post error or a script which doesn’t work as expected, I appreciate being notified.  My email is my first name at the domain name, and you are welcome to contact me that way.

Tags

1E ACLS Active Directory ActiveDirectory ADSI Advanced Functions Audit Change Administrator Password COMObject Computer Groups DateTime Desktop DNS Excel FileScriptingObject Forms General GPO GPS Group Policy Hacks ISE Lockout logons NAV740 Nessus OU OU permissions Outlook Pick Folder Power PowerShell Powershell Scriptlets RDP SCCM schedule reboot Scripting Security Shell.Application user information VBA Windows Update WMI WordPress WPF

Categories

akaplan.com

  • Back to Home Page

Archives

Scripting Sites

  • A Big Pile of Small Things
  • Adam, the Automator
  • Art of the DBA
  • Ashley McGlone
  • Boe Prox
  • Carlo Mancini
  • DexterPOSH
  • Doug Finke
  • Jaap Brasser's Blog
  • JeffOps The Scripting Dutchman
  • Jonathan Medd's Blog
  • Keith Hill's Blog
  • LazyWinAdmin
  • Nana Lakshmanan
  • PowerShell Magazine
  • PowerShell Team Blog
  • PowerShell.org
  • PwrShell.net
  • Richard Siddaway's Blog
  • Ryan Yates' Blog
  • Skatterbrainz
  • The Lonely Administrator

SQL Site

  • Art of the DBA

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2025 Alan's Blog | Theme by SuperbThemes

Terms and Conditions - Privacy Policy