Future events
Before starting with my summary of 2nd DuPSUG meeting, I want to inform you about some future events first:
- Dutch PowerShell User Group Meetings
- To keep track of news, use the links to LinkedIn, Facebook, Twitter and the RSS feed on the DUPSUG website.
- In the future, the plan is to meet every June and November.
- The next meeting will probably be at November 7th at VX Company.
- The idea is that community members will also present their own experiences, use cases, scripts, tools, methods. If you want to do so, please contact the DUPSUG group.
- Jeff Wouters might be able to arrange one or more copies of the PowerShell Deep Dives book from Manning since he’s contributing to it. The book isn’t complete and released yet, but Manning has an Early Access Program which means that you will get access to the completed chapters now and will get the full version when it’s done. Until June 13 there’s even a promotion to get a 40%-50% discount and it also applies to other great PowerShell books.
- Inter Access Microsoft Summer Summit (Hilversum, July 2nd 2013 17:30-22:00 CET)
- For more info and registration go to: http://interaccesssummersummit-es2.eventbrite.nl
This event
Last Thursday I attended the second Dutch Powershell User Group meeting in Hilversum hosted at Inter Access and sponsored by Sapien Technologies Inc.
Just like I mentioned in the summary of the first meeting there were manu interesting sessions that provided me with more insight and inspired me for practical uses. It was also great to discuss current developments with other knowledgeable and passionate people. The main differences with the previous meeting was that:
- This meeting was completely in Dutch, while the previous one was completely in English. As such, the workshop descriptions were also in Dutch and you needed to bring your own laptop.
- The format of this meeting was more of a workshop, while the previous one was mainly presentations.
Thanks go out to all attendees, especially those presenting, organizing and sponsoring the event. Special thanks to Daniel Bot for helping me fix a (stupid mistake in a) script I was working on 🙂
Goodies and giveaways
- Every attendee got a 7-day free pass for Interface Video Training.
- At random a person could win:
- Sapien Windows PowerShell video training
- Sapien PowerShell Studio 2012
- Active Directory e-book
Workshops / presentations
And now on with the really interesting stuff, the sessions/workshops. Below are the sessions with some info about the speakers and their sessions. I also added notes I took and other information I looked up afterwards. If you come across any errors or have comments, please leave a reply so I can fix it.
- Manage your network with Windows Server 2012
Ton Siemons | Slides and code | Website | Twitter | LinkedIn- The session covered:
- Installing and managing clustered / highly available Windows Server 2012 DHCP Failover environment.
- Managing DNS using PowerShell.
- Comparing the new PowerShell network related commands with some of the proprietary tools like ping and nslookup.
- Filter the available commands using: get-command *-net*
- The advantage of the PowerShell commands is that it returns objects instead of text. Also it can provide more options.
- By example compare nslookup with Resolve-DNSName and compare ping with Test-Connection.
- By example when you use “Test-Connection -ComputerName “localhost” -Quiet” it will only show True or False which can be more desirable in some cases than a complete blob of text as you get from ping.
- The workshop was performed by (ab)using Microsoft Technet Virtual Labs that provides free to use VMs hosted by Microsoft.
- We used the “Windows Server 2012 : Minimal Installation Shell” virtual Lab.
- This is a cheap, easy and safe way to test with PowerShell. The environment can only be used for 2 hours before it is reset though, so it might not be suitable for all.
- The session covered:
- Creating a Graphical User Interface (GUI) with PowerShell
Jeff Wouters | Slides and code | Blog | Twitter | LinkedIn- A great example of a PowerShell script with a GUI is LazyWinAdmin.
- A GUI for PowerShell can be leveraged using a couple of technologies including:
- Windows Forms (WinForms)
- Easier to create.
- Less options.
- Windows Presentation Foundation (WPF)
- More difficult to create.
- More options.
- An HTML application (HTA) GUI can be created as well and leverages WinForms.
- Out-Gridview
- Is included in PowerShell. You can just pipe to Out-Gridview.
- NET Framework 3.5.1 and the built-in script editor ISE must both be installed.
- Provides great filtering capabilities out-of-the box.
- Out-Gridview now includes a -passthru parameter which allows you to select objects that than can be passed to the pipeline for further processing. A simple example would be : Get-process | Out-GridView -PassThru | stop-process
- Is included in PowerShell. You can just pipe to Out-Gridview.
- Windows Forms (WinForms)
- There are many methods to create graphical user interfaces. Here are some examples:
- Windows Forms (WinForms)
- Creating it manually by coding it in PowerShell.
- Using GUI based solutions that allow drag and drop.
- PrimalScript Community Edition
- Free.
- More limited.
- If you want to modify your GUI, you have to re-add your custom code.
- PowerShell Studio 2012
- Commercial, 45 day trial
- More options.
- You can modify your GUI without having to re-add your custom code.
- PrimalScript Community Edition
- Windows Presentation Foundation (WPF)
- Coding it manually in PowerShell
- VisualStudio
- Windows Forms (WinForms)
- Some things to be aware of:
- When creating GUI tools, keep in mind that:
- Input validation is important.
- You might want to include prerequisite checks and output warnings to the GUI tool.
- You have to decide how to present users with information. Both for output and error messages.
- Sometimes you might want to include ways to refresh the content. By example if you’ve created a script that will allow you to stop a running process, you probably want to refresh the part containing the running processes.
- When using (rich) textboxes, to display output correctly use a fixed size font like Lucida Console, Courier New or Consolas.
- When creating GUI tools, keep in mind that:
- Some more interesting articles to help get you started with creating a GUI:
- Building forms withPowerShell Part 1 The Form
- GUI Creation with PowerShell: The Basics
- GUI Creation with PowerShell (Part 2): The Notify Icon or How to make your own HDD Health Monitor
- PowerShell GUI for your scripts. Episode 1-4
- Creating GUIs in Windows PowerShell 1.0 with WinForms
- Adding a Graphical Front End to your PowerShell Scripts
- How to Create a Graphical Event Log Viewer with PowerShell
- Sapien Blog containing many blog posts on GUI elements
- Building GUI Applications in PowerShell
- Building PowerShell GUIs with Primal Forms
- www.scriptinganswers.com
- WinForms control reference for powershell/
- When you’ve created your PowerShell script you might also want to create a .exe file. You can do this using a couple of applications including PS2EXE , PowerGUI , and even using other PowerShell scripts.
- Sapien is also moving towards packaging using MSI files, check out their limited preview of The MSI Wizard.
- Parallelizing PowerShell Workloads
Jaap Brasser | Slides and code | Blog | Twitter | LinkedIn- Take a look at the slides and code.
- Possible reasons to run code in parallel
- Execute tasks more quickly.
- Use system resources more efficiently.
- Have more control over how a series of tasks is being executed.
- Examples when parallelization is useful:
- When executing tasks on multiple systems.
- When executing multiple tasks on a single system.
- Examples of Cmdlets appropriate for parallelization
-
Get-WmiObject / Get-CimInstance
-
Get-ChildItem
-
Get-EventLog / Get-WinEvent
-
Testing connectivity
-
- Parallelization methods and comparison
- Invoke-Command -Asjob
+Can be used with Scriptblocks
+Easy to implement
– Relatively slow
– More limited than *-Job Cmdlets
– Only works if ComputerName is specified - Background Jobs
+Can be used with Scriptblocks
+Easy to implement
– Relatively slow - PowerShell Runspaces
+Fastest method. Very appropriate when starting man short tasks.
– More complex to implement. - PowerShell Workflows
+Survives being stopped and started. Can be useful by example for tasks that require restarts.
+Supports parallel foreach
– Has restrictions
-Slowest method for short living tasks.
- Invoke-Command -Asjob
- Script utilizing runspaces: Invoke-Parallel – Parallel PowerShell
- What are scriptblocks and how do you use them in PowerShell
Stefan Stranger | Slides and code | Blog | Twitter | LinkedIn- Take a look at the slides and code
- As the session was intended to be workshops, Stefan created a nice script where people only have to press <enter> after the script has been started. This way everyone could easily be on the same page without any typing errors. To start it, you have to “dot-source” the script. For those unfamiliar with it, I will describe what you have to do:
- Extract the content from the slides and code to a folder. By example “C:\My Files”.
- Start PowerShell (PowerShell ISE generated errors on my PC)
- Go to the drive you extracted to :
PS C:\Windows\System32> C: - Go to the folder containing the script files:
PS C:\Windows\System32> CD “C:\My Files\Scripts” - Dot-source the start-demo.ps1 script to get access to the start-demo function:
PS C:\Windows\System32> . .\start-demo.PS1 - Run the start-demo function and specify the demo file to start:
PS C:\Windows\System32> start-demo -file “start-demo -file .\1_What_is_a_ScriptBlock.txt - Type ? and press enter to see how you can navigate through the demo. In its simplest form, you just keep pressing <Enter>. Each part in a module is numbered. In the beginning of the line you could see [0]PS> or [15]PS>.
- After a file / module has ended, start a new one using:
- start-demo -file “start-demo -file .\2_Functions_And_Named_Parameters.txt
- start-demo -file “start-demo -file .\3_Filters.txt
- start-demo -file “start-demo -file .\4_PipeLining_Functions_And_Filters
- start-demo -file “start-demo -file .\5_Advanced_Functions.txt
- $input waits until all objects are collected
- By example used in sort-object.
- Compare the inputfunction and processfunction in the code samples to see the difference.
- When using TRY, CATCH, FINALLY for error handling, keep in mind that this will only work for terminating errors.
- If you want something that is normally not a terminating error to become a terminator error, you can:
- Set the erroraction for the Cmdlet to Stop if a Cmdlet supports it using:
-ErrorAction:Stop - Manually setting the global eror action preference to stop using: $ErrorActionPreference = “Stop”
Don’t forget to set this back to its original value!!
- Set the erroraction for the Cmdlet to Stop if a Cmdlet supports it using:
- To determine if the last error was a terminating error you have to check the value of $error[0].WriteErrorStream if you get something back it’s a non-terminating error. Otherwise it’s a terminating error. You can compare the differences using PowerShell (not PowerShell ISE):
- Get-Item C:\nonexistingfile
$error[0].writeErrorStream - Get-Item C:\nonexistingfile -ErrorAction Stop
$error[0].writeErrorStream
- Get-Item C:\nonexistingfile
- If you want something that is normally not a terminating error to become a terminator error, you can:
- As the session was intended to be workshops, Stefan created a nice script where people only have to press <enter> after the script has been started. This way everyone could easily be on the same page without any typing errors. To start it, you have to “dot-source” the script. For those unfamiliar with it, I will describe what you have to do:
- $PSBoundParameters
- Use $PSBoundParamaters to check in a function if a value had been provided to one of the parameters.
- Wrapping a command using $psBoundParameters and splatting. By example take the Get-WmiObject example and turn it into a Get-ComputerSystem command, while keeping all of the Get-WmiObject command parameters like such as -AsJob, -ComputerName, and -Credential.
- PowerShell Functions and Filters – The basics
- Take a look at the slides and code
Interesting PowerShell related stuff not related specifically to any of the sessions
- Using #region and #endregion to collapse / fold code regions
- List properties and methods of a command or object using get-member. Using get-member -force will show all. This is also useful for by example .NET and ADSI.
- Measuring PowerShell Scripts to improve your code.
- Here-String can be beneficial if you don’t want to have to resort to using many escape characters. It is also beneficial when using HTML and XML. For more info use “get-help about_quotation”.
- Backtick ` prevents interpreting the item after the backtick. By example `$variable will show $variable as string and not the value of $variable
- With PowerShell 3.0 “–%” can be used to more easily run CLI applications with (many) parameters.
- Conceptual help starts with About_ , view using : “help About_*”
- ScriptCS
- Script engine to write scripts similar to C#
- Use C# to expose objects to PowerShell
- http://www.beefycode.com/post/ScriptCS-or-PowerShell-part-1.aspx
- PowerShell 4.0
- Will be preinstalled in Windows Server 2012 R2 and Windows 8.1
- Is expected to become available for Windows 7 and Windows 2008 R2 and later.
- Default execution will be RemoteSigned.
- Will be enabled by default on servers.
- PowerShell 4.0 Desired State Configuration
- Microsoft announces PowerShell v4, DSC
- More PowerShell v4 and DSC Details
- Desired State Configuration (DSC) in Powershell version 4
- TechEd 2013 video : Desired State Configuration in Windows Server 2012 R2 PowerShell
- Use cases I can think of:
- Managing Cloud environments (including Azure)
- System Center Configuration Manager also has Desired Configuration Management (DCM) / Compliance Settings but seems to be aimed more towards on-premise environments.
- Continuous deployment / DevOps environments
- Consistent deployments through test, development, acception, production.
- Compliancy forcing / configuration drift prevention
- Auto-healing
- Enables the use of configuration files to be used by scripts.
- Managing Cloud environments (including Azure)
- An online Hands On Lab is also available now.
What I want/need to improve on
Ofcourse not everyone is on the same level of PowerShell knowledge and experience. You might also use it in a different way and with different purposes. The DuPSUG meeting triggered me personally to:
- Consider including feedback in my scripts to show users what parameters have been specified.
- Improve my error handling using TRY, CATCH, FINALLY. Especially I have to be more specific about what (not) to include in my TRY block.
- Take a better look at additional options for CmdletBinding and if there are some things I missed that might come in handy: Help About_Functions_CmdletBindingAttribute
- Learn more about splatting. I will revisit Jaap Brasser’s presentation of the 1st DuPSUG meeting and will also take a look at this PowerShell splatting series: Part 1, Part 2, Part 3, Part 4, Part 5. Besides having better readable code, I also like to be able to easily modify the value of a single parameter by using $splat.<parameter> = <value>. A good example would be to replace only the WMI class in: Get-WmiObject -ClassName Win32_Bios -credential $credential -server $server
- Look into using parameter sets to require an additional parameter to be set when I specify a specific one. By example I want to require a value for the parameter -logfilesavelocation if someone uses the -logerrors switch parameter.
- Wrapping a command using $psBoundParameters and splatting. By example for providing options to either include or exclude -Server and -Credential parameter.
- PowerShell GUI tool making.
- PowerShell 4.0 and Desired State Configuration (DSC). This is expected to become available with the Windows 8.1 preview and Server 2012 R2 preview around the 26th of June. I will also be looking at new Cmdlets introduced with Windows 8.1 and Server 2012 R2.
- Start measuring and parallelizing my scripts.
- Take a better look at the PowerShell documentation on MSDN. Including interpreting errors.
One response to “Summary of 2nd Dutch PowerShell User Group – DuPSUG meeting with additional resources”