RSS

Summary of 2nd Dutch PowerShell User Group – DuPSUG meeting with additional resources

08 Jun

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.
      • Remko Weijnen | Blog | Twitter | LinkedIn might be one of the people presenting at a future DUPSUG meeting.
    • 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)

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

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.

  • 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.
    • 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!!
        • 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
    • $PSBoundParameters
    • PowerShell Functions and Filters – The basics

Interesting PowerShell related stuff not related specifically to any of the sessions

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.
Advertisement
 

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

One response to “Summary of 2nd Dutch PowerShell User Group – DuPSUG meeting with additional resources

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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: