PowerShell User Group in Omaha Nebraska!

That’s right! We now have a PowerShell Users group in Omaha, Nebraska. Jacob Benson (Blog | Twitter) and myself are kicking off the inaugural session on 29 July @ 6:30 PM at the Microsoft office. If you are in Omaha or nearby, then you should most definitely be here to join the PowerShell community!

Oh yea, we also have an excellent speaker by the name of Don Jones (Blog | Twitter), whom you may have heard of Winking smile.  We will be working to line up more speakers for other meetings each month and will have those posted on the Powershell.org page.

Sign up here:

http://www.eventbrite.com/e/omaha-powershell-user-group-initial-meeting-tickets-11958049849 

If you have any questions, please contact either myself or Jacob and we will answer any questions that you may have. Also make sure that you follow the Omaha PowerShell Users Group on twitter as well!

Hope to see you there!

Posted in powershell | Tagged , , , | Leave a comment

NorCal PowerShell User Group Presentation on Runspaces is Available

I had the honor of being a speaker at the NorCal PowerShell User Group on June 10th in which I spent the time talking about using runspaces with PowerShell. If you didn’t have a chance to attend, the good news is that the video is now live on YouTube! I had a blast talking to the group about how you can utilize runspaces (and runspacepools) in a variety of situations as well as touching on a number of other related topics to include:

  • Runspaces
  • RunspacePools
  • Synchronized Collections
  • Locking a Synchronized Collection between runspaces
  • WPF UIs with runspaces
  • Performance and Speed with Runspaces and PSJobs

The presentation materials and example code is available here: http://1drv.ms/1imuQd0

Check out the video below!

Let me know what you thought about the presentation and anything else that you would have liked to see!

Posted in News, powershell | Tagged , , , , | 2 Comments

Prevent Write-Debug From Bugging You

If you are like me, you try to take advantage of already available methods of displaying output that displays information about a running function or script or  some other internal information by using Write-Verbose/Debug. The best thing about this is that it is simple to decide when to use it by specifying the various Write* commands anywhere in the code and as long as you have [cmdletbinding()] with Param() in the beginning of your code, all you have to do is use the appropriate switch (-Verbose or –Debug) and you can have that information out there to review.

The only problem that I would run into is the use of –Debug and those annoying confirmation prompts that always occur. You never see this with –Verbose and for that reason, I typically use that  so I do not get bombarded with a confirmation prompt each and every time I use it (that’s changed for me now and I will show you how it works later on). Take this example:

Function Foo {
    [cmdletbinding()]
    Param (
        [int]$Value
    )
    $iteration = 0
    1..5 | ForEach {
        $iteration++
        Write-Debug "Iteration: $iteration"
        $return = Get-Random -InputObject (1..$Value)
        Write-Debug "Return: $Return"
    }
}

This is a very simple function meant only to highlight the issue that I have been talking about. As soon as I run this function with the –Debug statement, I will see a confirmation prompt for each and every Write-Debug that exists.

image

Ok, once was enough, but this is out of hand. Even specifying “A” to continue with All operations seems not to work (there may be a logical explanation for this). Can you imagine having to do this for each and every Write-Debug call as well as accounting for each iteration that occurs? So why is this happening? Lets take a look and see what happens here.

Function Foo {
    [cmdletbinding()]
    Param (
        [int]$Value
    )
   
    $PSBoundParameters.GetEnumerator() | ForEach {
        Write-Verbose $_
    }
    Write-Verbose "DebugPreference: $DebugPreference"
 
    $iteration = 0
    1..5 | ForEach {
        $iteration++
        Write-Debug "Iteration: $iteration"
        $return = Get-Random -InputObject (1..$Value)
        Write-Debug "Return: $Return"
    }
}

I’ve added a couple of extra lines of code here to help see what happens when I run the function with the –Debug parameter. Viewing the $PSBoundParameters and $DebugPreference automatic variable will show us what is happening here.

image

I ran it first without the –Debug parameter and you can see that $DebugPreference is set to SilentlyContinue. The second run with the –Debug parameter shows a different story. We can tell in the $PSBoundParameters that it the parameter is being used, not a big thing, but looking at $DebugPreference now shows it has been set to ‘Inquire’, not the ‘Continue’ that I would have expected. Because of this, we will always receive a prompt for confirmation whenever –Debug is used.

Knowing this, I can now use a bit of code to make sure that when –Debug is used, I will not get a prompt each time it is used.

If ($PSBoundParameters['Debug']) {
    $DebugPreference = 'Continue'
}

I have the above code used at the beginning of my function so it will set the script scope of $DebugPreference to ‘Continue’ which in turn will make sure that I will not have a confirmation prompt. Let’s give it a spin and see what happens.

image

As you can see, I had 0 confirmation prompts and the script continued on showing my Debug stream. So with that, you now have an alternative to dealing with the Debug confirmation prompt the next time you decide to use Write-Debug in your code!

Posted in Debug, powershell | Tagged , , | 3 Comments

Speaking at NorCal PowerShell User Group in June

I’ll be speaking at the NorCal PowerShell User Group on June 10th talking PowerShell runspaces. I am honored to have been asked to speak to the group and look forward to chatting about runspaces and showing off some examples of what you can do with them as well as showing off some of the techniques that I use. Be sure to check it out if you have time! It will be recorded so if you do miss it, be sure to check back here for the YouTube link.

Sign up here for the meet up.

http://www.meetup.com/Northern-California-Powershell-User-Group/events/183848522/

Posted in News, powershell | Tagged , , , , | Leave a comment

Video From My Presentation at the Philadelphia PowerShell Users Group on WSUS and PowerShell

The video has been posted to YouTube from my presentation on May 1st at the Philadelphia PowerShell Users Group. My presentation was on Managing WSUS using PowerShell and I had a great time presenting on the subject. Check it out and let me know what you think!

Posted in News, powershell, WSUS | Tagged , , , , | 1 Comment