Skip to main content

Posts

Showing posts from February, 2016

Finding Your DSC Event Log Messages

Happy Friday!!! Often when I am writing large amounts of code, I like to enter items into an event log of some type.  For those of you who have been sitting in my Advanced PowerShell classes where we use SAPIEN PowerShell Studio, you may have noticed that I will sometimes include a tabbed page where I have a log file.    In DSC we have an Analytic log that we can send messages to using a DSC resource called Log, PS C:\WINDOWS\system32> Get-DscResource -Name Log ImplementedAs   Name   ModuleName                     Version    Properties         -------------   ----   ----------                     -------    ----------         Binary          Log    PSDesiredStateConfiguration    1.1        {Message, Depend... This log file contains all of the verbose messages sent to the Analytic log.   Look for Event ID 4098 with a ‘Warning’ level.   Warnings are represented with the value of 3. Unfortunately, not all event 4098 will be yours.  Take a look at this con

Using Calculated Properties with Select-Object

From time to time, I take a good look at how I am teaching PowerShell just to make sure that I am providing the most effective delivery.  That may be why when someone audits the class, they say they learn new material.  Besides, if I did not make changes, I would get bored. Over the last few months I’ve been teaching how to create calculated properties with Select-Object a little differently.  This is a key skill to have so I need to make sure that we get it right.  Here is an explanation of how to create a custom property. A custom property simply adds an additional property to an object in the PowerShell pipeline.  It does not change the original object, just the copy of it in the pipeline. Take a look at the properties of Get-Date. PS C:\> Get-date | Select * DisplayHint : DateTime DateTime    : Thursday, February 11, 2016 7:46:10 PM Date        : 2/11/2016 12:00:00 AM Day         : 11 DayOfWeek   : Thursday DayOfYear   : 42 Hour        : 19 Kind   

Using Invoke-CIMMethod

In my PowerShell class last week, we took a lab a bit further.  This lab involved using the old WMI commands.  Well, that is no fun.  I was providing my answers to the lab using the new CIM cmdlets. I did this once before, but I forgot to update my answers.  You see, there is a difference in how you provide information to Invoke-CIMMethod and Invoke-WMIMethod .  The objective was to change the Start Mode of the WinRM service.  To do this in WMI:        Get-WmiObject –Class Win32_Service –Filter "Name='WinRM'" |            Invoke-WmiMethod –Name ChangeStartMode –Argument 'Automatic' You would think that you could do the same with the CIM cmdlets, but PowerShell did not like this.       Get-CimInstance -ClassName Win32_Service –Filter "Name='WinRM'" |         Invoke-CimMethod -MethodName ChangeStartMode -Arguments 'Automatic' Invoke-CimMethod : Cannot bind parameter 'Arguments'. Cannot conv

Adding Some Animation into Your GUI

Yesterday, I posted some code on how to draw on a GUI using transparent colors.  To further demonstrate this transparency, we are going to add some animation. You can use your code from yesterday and just add to it.  The only object that you need to add is a timer control. Simply drag the timer control from the Toolbox in SAPIEN PowerShell Studio onto your form. The timer control will appear under he actual form in the Designer tab. Here are some differences from yesterday’s code.  (The entire code will be posted below) First we need to set the bounds for the circles to move.  They will be bouncing off the walls.  Remember that the ellipse origin is the upper left corner, not the center.  That is why our right and bottom boundaries are 156 and not 256.  The ellipses have a size of 100 pixels. # Set the X and Y max and min values. $XMin = 0 $YMin = 0 $XMax = 156 $YMax = 156 We need to declare the starting positions of all three ellipses.  Since