Alan's Blog

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

Menu
  • About My Blog
Menu

A GUI to Select Object Properties in Pipeline

Posted on May 14, 2016May 17, 2016 by Alan

My first attempt at a GUI to select objects properties demonstrated that I didn’t have a firm grasp on how to pipeline an object through an advanced function.  The problem I had at the time was not understanding how to have the form only appear once.  Why is that difficult?  Because the Begin Block won’t accept an variable created as an argument to the function.  If you put the form block into the Process Block, you get it popping up once for each item in the pipeline.  The desired result is to run the form just once.  The solution in my new version of Select-PropertyForm.ps1 is to create a variable to cause the form to be created only one time:

Begin{$FirstRun=$True}
Process{
if ($firstRun){
#  ... Form created here for first item only
$firstRun = $False
}
     #If they choose nothing or close, return all
     if ($Script:NewList[0].Count -eq 0){
        If ($ExitOnCancel) {Break}ELSE{$InputObject}
    }ELSE{
        $InputObject | select $Script:NewList
    }
}

End{}
} #End Function

Note from above that $script:NewList is a list of the selected properties.  The selection form looks just like the previous version:
.

I have added a parameter to the function to set the title.  This has been changed to a full advanced function.  You must include it in your own code or “dot source” it to run.

An example:

Get-aduser -Filter ('sn -eq "Smith"')  -properties * | 
Select-PropertiesForm | 
Convert-ADValues |
Export-CSV -NoTypeInformation "$env:userprofile\desktop\Smiths.csv"

This user the Get-User AD cmdlet to get all users with the last name of “Smith”, returning AD properties.  I then pipe to Convert-ADValues to ensure that dates and other values export okay, send results to CSV file.  The output for this is  Selected.Microsoft.ActiveDirectory.Management.ADUser

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