Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Need Help with Advanced Functions

$
0
0

Your code style is good; nice and readable with consistent bracing and indentation, plus good use of blank lines to group code into logical chunks.

In terms of functionality, you’ve kind of tied your GUI code and worker code together. It would have been cleaner to start with a function that takes a list of domains and usernames as input, determines which ones exist, and output objects with whatever properties you feel are needed (Domain, SamAccountName, Full Name, etc). Then you could write your GUI stuff around that function. You’ll see this type of code structure referred to as “tools” and “controller scripts” around here quite a bit: tools deal with objects (input via parameters and output to the pipeline), and tend to be placed into script modules. Controller scripts are written around tools, and deal with any user interaction, such as your menus, input and output files, etc. When you write the code this way, you retain the ability to run the tools directly from a command-line, even in an unattended script. The controller scripts, on the other hand, may require user interaction.

Aside from that, there’s just little nitpicky things. The -Verbose switch doesn’t do anything useful when you’re calling Write-Output and Write-Warning, for example.


Viewing all articles
Browse latest Browse all 13067

Trending Articles