Yearly Archives: 2015

PowerShell 5.0 RTM available for download

PowerShell 5.0, part of the Windows Management Framework 5.0 (WMF 5.0), is now released and available in the Microsoft Download Center.

WMF5Released

WMF 5.0 is currently available as a separate download for the following Windows versions:

Operating System Service Pack Prerequisites
Windows Server 2012 R2 .NET Framework 4.5 or above
Windows Server 2012 .NET Framework 4.5 or above
Windows Server 2008 R2 SP1 WMF 4.0 is installed and .NET Framework 4.5 or above
Windows 8.1
Windows 7 SP1 WMF 4.0 is installed and .NET Framework 4.5 or above

Currently WMF 5.0 RTM can be installed on older Windows clients, Windows 7 and Windows 8.1,  the updates can be downloaded. On Windows 10 WMF 5.0 is not available as an additional download as Windows Update can be used to update the Windows Management Framework.

Before installing WMF 5.0 on your system, please make sure that you read the released notes as there are currently known incompatibilities with the following products:

  • Microsoft Exchange Server 2013
  • Microsoft Exchange Server 2010 SP3
  • Microsoft SharePoint Server 2013
  • Microsoft SharePoint Server 2010
  • System Center 2012 Virtual Machine Manager

For more information please refer to the Windows Management Framework (WMF) 5.0 RTM Release Notes Overview on MSDN.

For more information on WMF 5.0 and the links in this article please refer to the links below:

Links in this Article
Windows Management Framework 5.0 Download
Windows Management Framework (WMF) 5.0 RTM Release Notes Overview
Known Incompatibilities
PowerShell Team – Windows Management Framework (WMF) 5.0 RTM is now available
Windows Management Framework (WMF) 5.0 currently removed from Download Center
Share

PowerShell Conference EU – Sessions have been approved

Earlier this week I received an email with a joyful message from the organization of of the PowerShell Conference EU. All three of my sessions that I submitted for the conference have been accepted so I am happy to announce that I will be speaking at the PowerShell Conference EU.

BannerSpeaker

The full schedule and all the presentations has not been announced yet, but it promises to be the event that cannot be missed in 2016. The location looks amazing from the pictures and from what I have heard it appears to be a great location. The combination of the speakers, the location and our shared passion for technology will make this into the event that cannot be missed in 2016.

HCCbanner

On the official website, PSConf.eu the event is listed as follows:
“Welcome to the next great European PowerShell event!

Deutsche PowerShell Konferenz and enthusiastic PowerShell Community Members from all across Europe have united together under the #PSConfEU banner to create an extraordinary PowerShell Community Event in Europe this coming April.

For this conference we will be bringing together PowerShell experts from all around the globe to create a unique 3-day event with presentations, workshops and the chance to connect, learn and discuss all things PowerShell with those that have a real passion for this evolving technology. There will be no place like this to deep-dive PowerShell in all of its flavors and colors.

The conference languages are English and German. There are continuous main tracks in both languages, making sure you can follow the tracks in the language you feel most comfortable with.”

For more information on this event, feel free to follow the official account on Twitter and the Hashtag to stay on top of the announcements.

Links in this Article
PowerShell Conference EU
Twitter – @PSConfEU
Twitter – #PSConfEU

 

Share

MSFest Prague 2015 – Slides and Code

MSFestBanner

At the end of November I had the pleasure to attend and speak at MSFest in Prague. This event aimed at the Czech IT Professional and Developer community had a wide variety of topics and I was asked to do two sessions on PowerShell. I presented the following two sessions:

  • PowerShell Security features and threat management
  • PowerShell Advanced Toolmaking

PowerShell Advanced Toolmaking

I have put the presentation and the code online in my Events GitHub repository.

All links in this article are available here:

Links in this Article
MS Fest Praha
Jaap Brasser – GitHub
MSFest Prague 2015 – Code and Slides
Share

PSBlogweek: PowerShell logging in the Windows Event log

This post is part of the #PSBlogWeek PowerShell blogging series. #PSBlogWeek is a regular event where anyone interested in writing great content about PowerShell is welcome to volunteer for. The purpose is to pool our collective PowerShell knowledge together over a 5-day period and write about a topic that anyone using PowerShell may benefit from. #PSBlogWeek is a Twitter hashtag so feel free to stay up to date on the topic on Twitter at the #PSBlogWeek hashtag. For more information on #PSBlogWeek or if you’d like to volunteer for future sessions, contact Adam Bertram (@adbertram) on Twitter.

Once you’re done getting schooled on everything this post has to offer head on over to the powershell.org announcement for links to the other four past and upcoming #PSBlogWeek articles this week!


An important part of PowerShell scripting is error handling, one of the main differences between a script and a one-liner for me personally is error handling and dealing with exceptions that might occur. For more information on error handling please refer to the previous PSBlogWeek articles where Boe Prox dives into use Try-Catch in order to catch specific errors.

When moving your scripts from into a production environment logging becomes more important, initially using plain text files for logging might be an appropriate solution. Another option however is writing logging information to the Windows Event Log. This has the benefit of being the centralized location where most logging takes place.

Writing to the event log is relatively simple, the Write-EventLog cmdlet can be used for this purpose:

PSBlogWeek2015-1

By taking a look at the error message we see that the PowerShell event source is not registered with the application log, in order to resolve this, we can write to the Windows PowerShell event log instead:

1
Write-EventLog -LogName 'Windows PowerShell' -Source PowerShell -EventId 12345 -EntryType Information -Message 'Script started'

PSBlogWeek2015-2

Notice how the command now successfully executes without the error message, this is because it is important for the script

Alternatively, it is also possible to specify a custom event provider, and register this to the correct event log as such:

1
2
New-EventLog -Source AwesomeScript -LogName 'Windows PowerShell'
Write-EventLog -LogName 'Windows PowerShell' -Source AwesomeScript -EventId 12345 -EntryType Information -Message 'Script started'

PSBlogWeek2015-3

It is also possible to create an entire separate event log for your script logging, also by using the New-EventLog cmdlet:

1
2
3
4
New-EventLog -LogName 'Scripts' -Source 'Your Script'
Write-EventLog -LogName 'Scripts' -Source 'Your Script' -EventId 12345 -EntryType Information -Message 'Script started'
New-EventLog -LogName 'Scripts' -Source 'Your Script2'
Write-EventLog -LogName 'Scripts' -Source 'Your Script2' -EventId 12345 -EntryType Information -Message 'Script started'

PSBlogWeek2015-4

To build upon this, it would be possible to create a script that logs when the script starts, executes an action, when an error occurs and when the script ends.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
begin {
    $EventHashInformation = @{
        LogName   = 'Scripts'
        Source    = 'Your Script'
        EventId   = 30000
        EntryType = 'Information'
    }
    $EventHashWarning     = @{
        LogName   = 'Scripts'
        Source    = 'Your Script'
        EventId   = 40000
        EntryType = 'Warning'   
    }
    Write-EventLog @EventHashInformation -Message 'Script started'
}
 
process {
    try {
        Get-CimInstance -ClassName Win32_Bios -ErrorAction Stop
        Write-EventLog @EventHashInformation -Message 'Successfully queried Win32_Bios'
    } catch {
        Write-EventLog @EventHashWarning -Message 'Error occurred while  queried Win32_Bios'
    }
}
 
end {
    Write-EventLog @EventHashInformation -Message 'Script finished'
}

PSBlogWeek2015-5

Using this method of logging allows for a dynamic form of logging where information such as the timestamp are automatically added to the information. A nice feature of using the event log is that it also allows for exporting the information directory to xml, for example:

1
2
3
Get-WinEvent -FilterHashtable @{
    LogName = 'Scripts'
} | ForEach-Object {$_.ToXml()}

PSBlogWeek2015-6

Because this type of logging can quickly fill up the event logs it is important to set the limits and the type of logging the event logs can do. In order to verify the current configuration, we can use the Get-EventLog cmdlet:

1
2
Get-EventLog -List | Where-Object {$_.LogDisplayName -eq 'Scripts'} |
Select-Object -Property Log,MaximumKilobytes,MinimumRetentionDays,OverFlowAction

PSBlogWeek2015-7

From this we gather that the Minimum retention of this log should be seven days and that only events older than 7 days will be discarded. If the event log is at the maximum size and there are no events older than 7 days to be discarded the latest event will be discarded and will not be written to the script. For more information on this subject please refer to the following MSDN article:
OverflowAction

Member name                                                                                                             Description 
DoNotOverwrite Indicates that existing entries are retained when the event log is full and new entries are discarded.
OverwriteAsNeeded Indicates that each new entry overwrites the oldest entry when the event log is full.
OverwriteOlder Indicates that new events overwrite events older than specified by the MinimumRetentionDays property value when the event log is full. New events are discarded if the event log is full and there are no events older than specified by the MinimumRetentionDays property value.

Based on the information in the article, we decide to increase the maximum size of log to 20 MB and to allow overwriting as needed, this is also referred to as circular logging:

1
2
3
Limit-EventLog -Maximumsize 20MB -Logname Scripts -OverflowAction OverwriteAsNeeded
Get-EventLog -List | Where-Object {$_.LogDisplayName -eq 'Scripts'} |
Select-Object -Property Log,MaximumKilobytes,MinimumRetentionDays,OverFlowAction

PSBlogWeek2015-8

With the information provided in this article you will be able to:

  • How to write information to the event log
  • How to register an event source to an event log
  • How to create a new event log
  • How to configure an existing event log

I hope this was informative and do not forget to read through the other #PSBlogWeek posts:

Links in this Article
Twitter #PSBlogWeek
#PSBlogWeek Announcement on PowerShell.org
MSDN Article: OverflowAction
Adam Bertram Blog
June Blender Sapien Blog
Jason Wasser Blog
Thom Schumacher Blog
Adam Platt Blog
Matt Johnson Blog

Share

Experts Live event in the Netherlands

Experts_Live_website_logo

Today Experts Live is kicking off in one hour, this is the biggest community driven event for IT Professionals in the Netherlands. There are more than 40 technical sessions presented by community and technical leaders and I am proud to be presenting here on PowerShell today.

ExpertsLiveSpeakerInfo

If you are unable to join the event today I will be sure to I will share the materials I presented over the next couple of weeks. For more information about this event, please have a look at the site here:
www.expertslive.nl

Share

New interview on PowerShell Magazine: #PSConfAsia An Interview with PowerShell Expert Jaap Brasser

Last month I presented at the PowerShell Conference Asia PowerShell MVP and organizer of the event Ravikanth pulled me aside for an interview for a few minutes in a new series on PowerShell Magazine: PowerShell Magazine TV. The full article is available here:
PSConfAsia An Interview with PowerShell Expert Jaap Brasser

Currently interviews are still being released so be sure to check out the other interviews as other experts give their insights on the past, present and future of PowerShell. It is an interesting series so be sure you don’t miss out on this.

PowerShell Magazine: #PSConfAsia An Interview with PowerShell Expert Jaap Brasser

The links mentioned in this article are also available below, feel free to access them for more information:

Links in this Article
PSConfAsia An Interview with PowerShell Expert Jaap Brasser
PowerShell Magazine
Media
PowerShell Magazine Founder Ravikanth
Share

Get-ZipFileProperties – Retrieve details about zip files

I uploaded a new function that can read details from zip files, for example the compression ratio and the number of files and folders that it contains. This function is based on a short article I wrote for PowerShell Magazine, Determine compression ratio of compressed files. I have uploaded this function to the TechNet Script Gallery.

Using the this function it is possible to view the details of a zip files, as shown in the following example:

.EXAMPLE
Get-ChildItem -Filter *.zip | Get-ZipFileProperties

Description
-----------
Use Get-ChildItem to retrieve a list of zip files in the current folder and pipe it into the Get-ZipFileProperties function to retrieve information about these files

GetZipFileProps

For more information or the direct download links of these scripts please refer to the links below. Feel free to leave a comment either here or in the TechNet Script Library.

TechNet Script Gallery
My entries in TechNet Script Gallery
JaapBrasser.com – Scripts
Get-ZipFileProperties – Script that retrieves details about zip files
Share