Saturday, November 22, 2014

Using Pre-Release Software Not Always A Great Experience

Over the years in the industry, I've had the opportunity to use pre-release software. Some of it has been pretty awful, while others perfect or nearly so – and more in between. Using software that has not been richly tested is always a bit of a gamble, although some vendors are better than others. Of course, issues during pre-release typically get resolved prior to general release – so these errors really only affect those of us mad enough to use beta code!

With that in mind, I downloaded the latest build of PowerShell V5 as soon as it was released. I was anxious to see what, if anything, had become of the Chocolatey provider for Find-Package (OneGet) as it had been removed in an earlier beta version (as previously noted!). So my first test was to do both Get-Module and Get-Package to see the two 'get' package managers in action.

Much to my surprise, running Find-Module produced a ton of errors:

imageWeird, to say the least. I tried to see if other beta testers were seeing this issue the ones I was able to chat with did not see this error. Then I was having a Skype conversation with Aleksander Nikolic who asked me what culture I was using. As you can see in the above screen shot, I'm using my home culture (en-GB). He suggested it was culture related. To test this, I spun up an Azure VM, loaded the new version of PowerShell V5 and, as if by magic:

imageJust as I expected! This looks to be another culture issue – one that will no doubt be sorted out by the time RTM comes around (or, hopefully, a newer build is released that works with En-GB).

It's easy to understand this issue, but I guess I'd have been less surprised and frankly less disappointed, if the issue had been mentioned in the otherwise excellent release notes (or possibly even acknowledged in the release notes). One for the future perhaps.

So for the foreseeable future, I'm stuck with using a partly broken beta build. I can live with OneGet being broken in exchange for the other goodies in V4. And yes, this bug has been reported on Connect (https://connect.microsoft.com/PowerShell/Feedback/Details/1037088). Feel free to vote it up!

The joys of using Beta software!

Friday, November 21, 2014

A New Build of PowerShell – Chocolatey Regained

Having posted previously about a recent PowerShell V5 interim build that resulted in Chocolatey not being available by default – as if by magic, Microsoft have issued a new build of PowerShell V5 Preview AND it's includes Chocolatey by default. You can get more details from the PowerShell team Blog.

This build only operates on Windows Server 2012 and 2012 R2, and Windows 8.1.

Technorati Tags: ,

Wednesday, November 19, 2014

Yet Another PowerShell V5 Preview Build!

Microsoft has just released a updated build of PowerShell V5. I am particularly excited at the sheer pace of progress that is in evidence. Many features, particularly Desired State Configuration, are unfinished – works in progress. But what progress is being made!

To get the new build, go here: http://www.microsoft.com/en-us/download/details.aspx?id=44987. This link has the binaries for X64 and x86 systems plus one for what appears to be windows RT, which would be very cool. More on this when I get home to play on my RT Windows Surface device.

In the mean time: let the downloads begin!

Technorati Tags:

Tuesday, November 18, 2014

Chocolatey Lost, Chocolatey Found

A possibly obscure blog post title, but please read on. In PowerShell V5, Microsoft includes two cool modules: PowerShellGet and OneGet. PowerShell get is meant to find and manage PowerShell modules while OneGet is meant to find and manage 'packages'. This allows you to search for, download and install a substantial library of software and a library of PowerShell modules. This is a great way to leverage the community!

In the first drop of PowerShell V5, Get-Package got it's list of packages, inter alia, from Chocolatey a Windows friendly package provider. But unfortunately, the link to Chocolatey was removed in the latest V5 drop. I'm not sure why, although I'm sure there is a sensible explanation. And after all, this is a work in progress. But no matter why it's gone – I want it back. Turns out it's pretty easy to do that.

To setup Chocolatey as a package provider in the latest V5 drop, it's easy:

Register-PackageSource -Name chocolatey -Provider PSModule `
-Trusted –Location http://chocolatey.org/api/v2/

Life is so simple when you know how! And once you do that, Find-Package returns a LOT more packages. SO happy hunting.

I am looking forward to more clarity around the differences between OneGet and PowerShellGet, particularly in how Enterprises are meant to make use of them. I can see several approaches that could be taken and hope to see more information as we progress towards the release of PowerShell V5.

Technorati Tags: ,

Wednesday, November 12, 2014

Microsoft takes .NET Open Source AND Cross-Platform

Microsoft has this week announced that it is providing the full .NET Server stack into Open Source. This includes ASP.NET, the .NET compiler, the .NET Core Runtime including the Framework and Libraries. This Microsoft says this should enable "developers to build with .NET across Windows, Mac or Linux".  For the details, see http://go.microsoft.com/fwlink/?LinkId=518340

And as if that were not enough Open Source goodness, Microsoft also announced Visual Studio Community 2013 – a free, fully featured version of Visual Studio including full extensibility.  Developers, or anyone else interested, can get started with Visual Studio Community 2013 HERE.

Wow!

Technorati Tags: ,

Tuesday, November 11, 2014

CBT Nuggets Publish a Course for Microsoft Exam 70-337

I see that CBT Nuggets have just announced the release of their video training course Microsoft Lync Server 2013 70-337.

This course covers all the key parts of the syllabus for the 79-337 exam along with some exam preparation tips and a case study to help you further prepare.

I've not yet looked at the videos in the course, but CBT Nuggets material is usually of a good standard. I'd be interested in any feedback.

Monday, November 10, 2014

Writing Classes With PowerShell V5-Part 1

As I noted in previous blog posts (here and here) one of the many cool features coming with PowerShell V5 is the ability to develop Classes and Enums using PowerShell. in Monday's blog post, I showed how you could create an Enum, one important construct useful to creating classes.

Before I look at creating classes with PowerShell V5, it might make sense to go over what a class is and what creating them means. Many PowerShell users may be under familiar with the concepts involved.

Classes

The first thing to cover is classes. But what IS a class? A class is the definition of an object. In PowerShell everything you do relates to instances of objects that belong to some class. If you issue Get-ChildItem on the file system provider, you get zero, one, or more object occurrences, or instances, of either the System.Io.DirectoryInfo or System.Io.FileInfo classes. The number 42 is an object of the class System.Int32,

The Class defines the object (and occurrences of that object). Each class has a number of members. These include constructors, properties, and methods. The constructor is how you create a new class instance (creating a System.Io.Fileinfo object (instance) pointing to c:\foo.bar.ps1). Properties are attributes of object are actions you can apply to the object, such as the name of a file. The  properties and methods of a class can be either static (belonging to the class) or dynamic (belonging to a class instance). This is a difference new PowerShell – see below for more on the difference.

Constructors

A constructor is code that creates a new instance of the class. Constructors can take parameters that describe the object instance to be created. You can also overload constructors – creating more than one constructor with different sets of parameters. In the System.Net.Mail.MailMessage class, you can see 4 different constructors; one takes no parameters, while the other three take different sets of parameters, as you can see in MSDN. Each constructor creates an object instance (a mail message) but with different properties.

Properties

A properties is some attribute, either of the class itself or of an class instance. For example, the class [system.int32]. Each property has a type and this can be a value type (such as a string, or an integer) or a more complex object. An occurrence of the System.Net.Mail.MailMessage  class, for example, has a simple Priority property that takes a string (Low, High, Normal). It also has a property, To, which takes an object of the class System.Net.Mail.MailAddresss. The point here is that an object instance (a mail message) has a property (to) that itself is an object which has properties (e.g. DisplayName). Of course, that property too could be an object etc etc (although in the case of System.Net.MailAddress it doesn't!).

Methods

A method is some function that the class is capable of performing – either on an specific instance (a dynamic or instance method) or based on the class (a static method). Dynamic methods usually do something to the instance, while static methods do something that relates to class itself. The System.Int32 class, for example, has both static and instance based methods. Individual instances of the the System.Int32 class contain methods that convert the instance's value to another form (e.g. Boolean, or System.Int64, etc). Those dynamic methods work on the the instance of the class. The ToString method on instances of System.Int32 converts the value into a nicely formatted string, with the help of a CultureInfo object, like this:

image

Static Methods and Static Properties

One concept that many new-to-PowerShell folks find harder to understand is concept of static (vs dynamic of instance) methods and properties. A static method is a method that does not make use of a specific instance of the class. Instead it works by doing something class related. The System.Int32 class has a neat static method, Parse. The Parse method takes a string and either parses that string into a 32-bit number or raises an exception if it can't correctly parse the string.  The PowerShell Syntax to invoke a static method is: [<class name>]::methodname(<array of method parameters, or nothing>]. For example:

[System.Int32]::parse('42')

The System.Int32 class also has static properties or properties of the class. For example, MaxValue is the largest value that a System.Int32 can hold, while MinValue is the smallest value. In PowerShell, the Syntax for static properties is: [<class name>]::<propertyname>.

Here is an illustration of static methods and properties.

image

As you can see in this screen shot, the Parse method parses nicely the string '42' into a 32-bit integer. But the string ('4223452354234523452345235234'') could not be parsed and the Parse method threw an exception, the Overflow exception, as you can . You could use the Parse method inside a Try/Catch block to, for example, validate that some value passed in from a user is of the right form (i.e. a 32-bit integer) and catch and handle any exceptions to that validation.

A static property is some property related to the class not an instance. System.Int32 also also has some static properties, including MaxValue (the largest 32-bit integer), and MinValue (the smallest integer).

Creating Object Instances

PowerShell users typically create the object instance by using cmdlets (or functions, aka script cmdlets). Thus you use Get-ChildItem cmdlet and get instances of System.Io.FileInfo and/or System.Io.DirectoryInfo classes. In most cases, you process the objects instances by using cmdlets for example using Set-ADUser to update user information in Active Directory. Best practice says to use cmdlets where you can and only then drop down into lower level code.

There are three ways you can create new instances of an object (class). The first is via a cmdlet, but in the absence of cmdlets/functions, then you can either  use a static method of the class or use the New-Object cmdlet and specify the class of which you wish to create an instance. One example is the  class System.Guid, which it defines and manages guids. There are no cmdlets to manage this object type. If there had been, then you would most likely have a New-Guid cmdlet to create a new guid. Since that cmdlet does not exist, to create a new guid, you use a static method, like this:

.

image

The other way to create new instances is to use the New-Object cmdlet. This cmdlet uses the class constructors available and matches the parameters you specify with the various constructors. For example, you can create a new instance of the System.Mail.Mailmessage class using one of four constructors. To Create an empty mail message, you would do this:

# Create an empty massage
$EmptyMsg = New-Object System.Net.Mail.Mailmessage

# Create a message from and to
$To= 'tfl@psp.co.uk'
$Fm='doctordns@gmail.com'
$MailMsg = New-Object System.Net.Mail.MailMessage $Fm, $To

So What?

In Windows, Microsoft and other vendors have provided thousands of cmdlets, but as yet, there is not full coverage of all the objects in the .NET framework. Thus if you need to use objects of those types (belonging to some less well known .NET Class). A good example is localisation. If you want to present a price in say US$, Norwegian crowns and UK Pound sterling. Assuming you know how to use the ServiceEx web services, the script looks like this:

# Get Curency conversion rates
$From = 'GBP'
$Tous  = 'USD'
$Tono  = 'NOK'
$CurrencyConvertor = New-WebServiceProxy "
http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"
$USrate = $currencyConvertor.ConversionRate($from,$tous)
$NOrate = $currencyConvertor.ConversionRate($from,$tono)

# Calculate price
$priceUK = 12345.669
$priceNO = $PriceUK * $NOrate
$priceUS = $PriceUK * $USrate

# Convert to nice strings
$usinfo = [System.Globalization.CultureInfo]::CreateSpecificCulture('en-us')
$Noinfo = [System.Globalization.CultureInfo]::CreateSpecificCulture('no-nb')

"The UK price is:  $($PriceUK.tostring('c'))"
"The NO price is:  $($priceNO.tostring('c',$noinfo))"
"The US price is:  $($priceUS.tostring('c',$usinfo))"

And the output looks like this:

image

Pretty easy, when you know how to manage .NET classes and can use XML web services. The .NET framework contains a wealth of classes that have value, depending what you are working with. Being able to just reach out and grab them, when there are no cmdlets, provides you with a lot of power. Plus, if you understand what is going on with objects, troubleshooting scripts becomes easier – if nothing else, the error messages may make a bit more sense.

In the next article I'll look at actually combining the information presented here with how to create these things using PowerShell V5.

 

PowerShell Desired State Configuration – More Resources

As noted on the PowerShell Team Blog,  Microsoft has published many new experimental resources for Windows PowerShell in the form of the DSC Resource Kit Wave 8. This latest release brings the number of rerources available to over ONE HUNDRED (138 for those of you who are counting – a 53% increase from the earlier release).

The sheer number of resoures now available is staggering – and I expect the pace of delivery here to continue as the team approach RTM for PowerShell 5 and Windows 10.

As Clifton Chenier sings: Laissez les bon temps roulez.

Tuesday, November 04, 2014

Writing Better PowerShell Scripts with ISESteroids

I’ve been working a lot recently with a nice package called ISESteroids.  As an ISE user, the name got my attention before anything! As the name kind of indicates, the package improves PowerShell’s Integrated Scripting Environment.

So what IS ISESteroids? ISESteroids is a commercial module that you add into the ISE converting the ISE from a good development tool into a much better one. My view is simple: ISESteroids makes me able to write better code, more legible code quickly and easily.

Installing ISESteroids is trivial. Just download the package (it comes as an archive), unblock the archive (after download, right click the archive, select properties then select unblock). Then create an ISESteroids folder under your modules folder, and copy the contents of the archive there.  It should look something like this:

image

Once the module is in place, you just need to add a line to your ISE Profile:

Start-Steroids

The first time you run this cmdlet, you have to accept the license agreement, but after a second or two, you can start to experience the added value ISESteroids gives you.

But what is that, I hear you say? There were several things I noticed after first installing ISESteroids. The first of which is that the whole UI changes. The top part of the ISE has the original tool bar expanded and with a second pull down tool bar with more tools. Plus the tool bar at the bottom of the ISE window has been enhanced and now includes a community information feed. This bottom tool bar also has a REALLY nice feature I’ve always wanted – the ability to just take the last command typed at the console and put it into the edit tab. 

Here’s a before and after look (without, then with ISE Steroids installed and running)

image

versus

 image

The community feed at the bottom is a very nice touch, although all the new tools was surprising (in a nice way). After using it a bit, on a  system without ISESteroids, the ISE felt somewhat more primitive (not unlike using PowerShell V2’s ISE today!).

All those extra tools and a lot of the features in ISESteroids are focused on helping you to write better PowerShell code and streamlining that process as much as you can. In short: good practice built in, and more, more, more automation of the code development process.

Once I started writing scripts with ISESteroids enabled  I saw some changes in the ISE’s Edit pane. Some language elements were marked with a ‘squiggle’ underneath. And the edit pane itself has been reformatted with some new elements. Here’s an example of a very simple script

image

Just above the number 1 and 2 are two things ISESteroids ‘complains’ about. The first thing is that I used an alias (LS) instead of the full cmdlet name (Get-ChildItem); the second thing is that I am using a string but it is delimited with a double quote, not a single quote. Single quotes, unless you are including variable expansion, are less performant. The third cool thing shown here is that ISESteroids keeps track of functions and shows you how often they are referenced. You can see here the FOO function was referenced just once just once. The final thing to notice is the new search bar – just type a function name, and PowerShell, jumps to that function definition in the code. Great for when you need to update a function definition you call a dozen times in your script!

ISESteroids also makes it easy to get rid of those squiggles. To fix the two issues above, you just hover over the bottom bar in the ISE windows and ISESteroids pops up messages like:

image

image 

This makes it really simple to fix issues like this. I would have liked to have been able to just right click over the squiggle and select the fix from there – but the bottom of the window works too.

As you delve into using the ISE, just about every menu and tool bar is expanded. To name a few:

  • The File Menu now has an sub menu to open your profile files (you can open both console and ISE profiles).
  • The file Menu also has a Print menu item.
  • The Tools Menu now has a couple of new tools and options.
  • The Add-ons menu has new menu items for moving tool panes around the ISE UI. Useful if you are using some of the tools!

This is just scratching the surface. I’ve got a bit of a coding project coming up and so will be using ISESteroids more heavily and will gladly provide more feedback.

For more information about the product, see the documentation: http://www.powertheshell.com/isesteroids2/documentation/.

One final thing – ISESteroids is not a free product. Single use is €99 although there are volume discounts. BUT because the author is such a fan of the community, he has created what they call their ‘Helping Hands Programme’ – in effect they offer free NFR (not for resale) personal ISESteroids 2.0 Enterprise license in exchange for 3-5 hours of your work, helping them to  make ISESteroids better known, and better documented. A very generous offer!

In summary, ISESteroids is a tool that adds value to the PowerShell ISE and helps you to write  better scripts. If you are writing scripts and other PowerShell related artifacts as a key part of your job then this product is certainly worth the money.

Technorati Tags: ,,

Monday, November 03, 2014

Enums in PowerShell V5

As I noted in an earlier blog post, we have begun to see the contents of what eventually is to become PowerShell V5. Amongst the cool features that are to be delivered in V5, one of my favourite is the ability to define Classes and Enums in PowerShell. I'll leave Classes for another day (and possibly multiple blog posts), but let's look at Enums.

First, what is an enum? An enum is a type that create a list of named constants. In the .NET Framework, you find the System.Enum class – which implements enums.

You can think of an enum as all the proper values that some parameter can take. For example, if you were implementing a pizza application, you might have an enum called PizzaSize, representing the available sizes of pizza and another enum called PizzaToppings that contains the valid names of all the toppings you can put on your pizza.

Of course, you could have always used the ENUM feature of .NET, and there are a lot of enums already defined.  For example, System.Net.Mail.MailPriority is an existing enum in the .NET Framework 4.5, which specifies the valid values for mail priority. This is a simple enum, with just three values: High, Low and Normal. If your code/script/function is passed a value for mail priority, it's always a good idea to validate it – and here's some PowerShell Code that can do this:

# Enums.ps1
Function Confirm-MailPriority {
param ([string] $mailpriority)
if ([enum]::IsDefined(([System.Net.Mail.MailPriority]),$mailpriority))
   {Return $true}
Else
   {return $false}
}

This function takes a string representing mail priority and returns true or false depending on whether it's valid. Here is the results of testing this function:

image

Now as you can see – the validation is case sensitive – thus 'High' is a valid mail priority, whereas 'high' isn't. You can get around that by fully spelling out the enum, and letting .NET work out the validity. Thus 'high' is invalid whereas [System.Net.Mail.MailPriority]::high (and [System.Net.Mail.MailPriority]::High) are both valid. This matters a lot if you are calling .Net method and passing enumerable values (e.g. mail priority). 

Up until Version 5 of PowerShell, you could always use the [enum] class to validate and list all the valid values of existing Enums. But what you did not have, up till now, is the ability to create a real Enum in PowerShell. Of course, you could have used Add-Type, and specified the C# code but I don't regard that as quite the same thing as defining an enum in PowerShell directly.

In V5, it's trivial to create an enum.  Just specify it's name, follow it by a script block with each enumerable value on a separate line. Like this:

Enum PizzaSize {
  Small
  Medium
  Regular
  Large
  ExtraLarge
}

Note there are no commas separating the values,just a newline. I wonder if this is a limitation of the current release and maybe additional delimiters will come in later versions. We'll have to see!

Once you define this enum, you can then use the enum and can validate it:

$size = [pizzasize]::large
[enum]::IsDefined(([pizzasize]),$size))  # True!

This is pretty cool – and lays at least part of the foundation for you to be able to develop full .NET Classes in PowerShell. 

There is at least one limitation I am aware of with Enums in PowerShell and that is that they are not persistent. Unlike the .NET Framework enums which are always available (one the relevant .NET Class Library is loaded!), you need to define enums in each script that uses them. That is, thinking about it, not such a great limitation – you just need to define your enums where you use them.

My preferred place is as as part of a module definition – just put your enums for your module in a file such as Enums.ps1 and put it into the module folder. Then, in the ScriptsToProcess key of the module's manifest, just specify Enums.ps1. That will dot-source them into your global environment and are then available for all the code you then run.

Enums are one important part of being able to develop a class in PowerShell. I'll be developing another article to describe how that works. I will probably wait till after the next drop of PowerShell V4, which is scheduled for November some time.

Technorati Tags: ,,,

Sunday, November 02, 2014

PowerShell OneGet Monthly Call

I am not quite sure how this got out here, but am glad it did. This (https://t.co/mkafiMJR9T) is a web cast covering the current state of play with the OneGet feature of PowerShell V5.

This is awesome stuff – keep it up!

Spam and IM

In a number of documents relating to OCS and Lync,  I've seen discussion of Spam over IM (SPIM). I've not really seen much decent discussion of it, other than it's an issue. Most of the material seems to assume you know all about SPIM.

For those that are not familiar, you might want to look at RFC 5039. This document provides some great background in SPIM and other malevolent IM related stuff.

Technorati Tags: ,,,

Wednesday, October 22, 2014

Managing Zip Files with PowerShell V5

In a recent blog post, I noted the arrival of PowerShell V5 preview within the technical preview of Windows 10. A slightly later version than is available for installation on down-level operating systems ( I use the latest V5 preview version both on my Windows 8.1 laptop and my main home workstation (which runs Server 2012 R2).  While Desired State Configuration is the ‘big’ new feature in V5, there are a lot of other cool features in V5, including the ability to manage zip files with PowerShell.

The later V5 preview versions come with two new cmdlets or managing  ZIP files:

  • Compress-Archive
  • Expand-Archive

The Compress-Archive cmdlet takes an array of file names (specified via the –Path parameter) and compresses them into an archive file (specified by the -DestinationPath Parameter). You can also specify the level of compression – the valid values are NoCompression, Optimal, Fastest. Fastest means that the compression is less than  Optimal, but Optimal should produce slightly smaller .ZIP files. Optimal, however, takes more CPU time – but there’s not much difference for smaller files. To have Compress-Archive update some or all the files in the archive, use the –Update parameter. This parameter updates the archive with the specified files. Thus you can update a single file in an archive should the need arise.

The Expand-Archive cmdlet expands the files in the archive (specified by the –Path parameter) into the folder specified by the –DestinationPath parameter. To avoid being asked for permission to do the expansion, you can speciy the –Force parameter.

 

Here’s an example of some archive file manipulation

 

PSH [C:\foo]: ls c:\foo\*.txt

    Directory: C:\foo
Mode                LastWriteTime         Length Name                                         
----                -------------         ------ ----                                         
-a----       26/07/2014     15:59            431 atia.txt                                     
-a----       19/06/2014     17:25          18890 history.txt                                  
-a----       06/03/2014     15:09           1027 hosts.txt                                    
-a----       06/08/2014     10:05             37 NAMES.TXT                                    
-a----       24/09/2014     06:58           1877 trans1.txt                                   

PSH [C:\foo]: (ls *.txt | measure -sum -Property length).sum
22262

PSH [C:\foo]: Compress-Archive *.txt -DestinationPath .\aaa1.zip -CompressionLevel Fastest

PSH [C:\foo]: Compress-Archive *.txt -DestinationPath .\aaa2.zip -CompressionLevel Optimal

PSH [C:\foo]: Compress-Archive *.txt -DestinationPath .\aaa3.zip -CompressionLevel NoCompression

PSH [C:\foo]: ls c:\foo\aaa?.zip

    Directory: C:\foo

Mode                LastWriteTime         Length Name                                         
----                -------------         ------ ----                                         
-a----       21/10/2014     18:33           2172 aaa1.zip                                     
-a----       21/10/2014     18:33           2039 aaa2.zip                                     
-a----       21/10/2014     18:33          22783 aaa3.zip                                     

PSH [C:\foo]: Expand-Archive c:\foo\aaa1.zip -DestinationPath c:\foo\expanded -Force

PSH [C:\foo]: dir .\expanded

    Directory: C:\foo\expanded

Mode                LastWriteTime         Length Name                                         
----                -------------         ------ ----                                         
-a----       21/10/2014     18:34            431 atia.txt                                     
-a----       21/10/2014     18:34          18890 history.txt                                  
-a----       21/10/2014     18:34           1027 hosts.txt                                    
-a----       21/10/2014     18:34             37 NAMES.TXT                                    
-a----       21/10/2014     18:34           1877 trans1.txt
                                   

In summary, two new and somewhat overdue cmdlets that make your life easier!

Technorati Tags: ,,,

Monday, October 20, 2014

Another PowerCamp is Over

Last weekend, I held another PowerShell PowerCamp event – we had 19 attendees in all for two days of PowerShell. It was a great weekend, topped off by Tom Arbuthnot coming in on the Sunday to deliver a guest lecture.  I really enjoyed it, but it was a lot of work! And from the mail I've had, the attendees got a lot out of it.

Thanks to the folks at Microsoft, particularly Claire Smyth, for all their help in making the weekend a success.

During the event, there were several ideas put forward to a next event. One suggestion was a more advanced weekend, particularly looking at DSC and the new things in Version 5. A V5 PowerCamp could be fun! Ideas as to future events are most welcome.

Technorati Tags: ,

PowerShell Version 5 in Windows 10 Preview

Like a lot of people, I’ve downloaded and been playing with the previews of Windows 10 (client and server). About the first thing I did was to check out PowerShell and was delighted to find it contains a very late drop of the PowerShell V5 code – marginally later than the WMF Preview shipped in September.

My Server 2012R2 workstation, which has the September V5 drop reports:

image

Meanwhile, in the Windows 10 Server preview, we see:

image

As you can see, Windows 10 has a slightly newer version of PowerShell V5. The release notes don’t clarify what has changed, but I’d have expected the 9841 to be just a bug fixed fork of 9814.

This new version of PowerShell brings some big changes, not least of which is the improvements and enhancements to Desired State Configuration – no doubt this will feature large in the eventual launch of Windows 10 Server (Server 2015??).

But there are also a bunch of smaller changes that I also am very keen to see go mainstream. These include:

  • Archive (.ZIP file) cmdlets
  • Changes to –item noun to enable symbolic links
  • The ability to develop classes (and enums) using PowerShell
  • Improvements in DSC authoring within the ISE
  • PowerShell transcripts within the ISE
  • Better script tracing

PowerShell V5 looks like being a block buster! I’ll be writing blog articles about each of these new features along with some usage of them for your delight!

Technorati Tags:

Tuesday, September 30, 2014

PowerCamp Power Guest–Tom Arbuthnot

On Oct 18/19th, I run the next PowerShell PowerCamp – a 2 day PowerShell jump start event. Over the course of 2 days, I run through the basics of PowerShell – from Cmdlets/Objects/Pipelines, through formatting, the ISE, the language and its syntax, functions and modules, and Desired State Configuration (DSC). You bring your laptop and while I’m lecturing, you are banging out PowerShell to manage a set of VMs you bring along!
As part of the event, I always try to get another guest speaker, who I ask to talk about PowerShell in general. What are the things they have learned (which attendees will have to to)? What are their best practices? For this event, I am pleased to announce we will have the presence of Tom Arbuthnot, a superstar Lync MVP and Lync Consultant (and a Lync MCM!), and a great PowerShell evangelist. Tom’s spoken before at these events, and his talks are good and very entertaining.
I still have a few places left on this event – so if you want a great jump start to PowerShell, or to review the basics and more, then contact me at DoctorDNS@Gmail.Com !

Thursday, September 18, 2014

Azure for Longer Term Backup

I’ve been teaching the AOTG (Ahead of the Game) partner training around the UK, and shortly in Eire. It’s been very interesting talking to Microsoft’s SMB partners and looking at how they sell and utilise Azure. One of the Azure Products this training is advocating is Azure Backup. Last week, when I was teaching this in Manchester, one delegate pointed out that the big downside to Azure backup was that there was not much of a retention period and as such was not helpful to the delegate’s customers.

Fast forward a few days, and the wish has come true. I had a conference call this morning with the Azure backup who told me that this request had been heard loud and clear and is now in place. He pointed me to the blog post at: http://azure.microsoft.com/blog/2014/09/11/announcing-long-term-retention-for-azure-backup/

Sure enough, you can get all the backup you need (well all reasonable backups!). And the maximum retention period is 9 years, as the blog post explains.

One word: Awesome!

del.icio.us Tags: ,,

Saturday, August 30, 2014

Documentation–documenting variables in a script/function

A few weeks ago, I gave a PowerShell course during which the issue of documentation came up. The point I made was documentation is a good thing – and the more the better. The delegates really liked the comment based help approach. But it often does not go quite far enough.

One additional thing you can do is to document individual variables. Each variable object lives in the Variable: drive. Variables are , like everything PowerShell, an object. When you get child items of a variable, the variable is returned of the type System.Management.Automation.PSVariable. There are some special PowerShell variables (QuestionMarkVariable, LocalVariable, SessionStateCapacityVariable, and NullVariable). All of these objects have a Description property which enables you to describe each variable.

So you could do this:

$I = ‘10.0.0.100’
(dir variable:I).description  = ‘the new IP address for the new server’
$iold = ‘10.0.1.200’
(dir variable:iold).description  = ‘the new IP address for the new server’
Dir Variable: | Format-Table name,description –a

I’ve not used this approach much, but I probably do so in the future for production scripts at least!

Friday, August 29, 2014

Desired State Configuration Resource Kit–Wave 6

The PowerShell team has just released an update to the DSC resource kit – bringing the total number of DSC resources to over 80! While the bulk of the resources in the resource kit are ‘experimental’ – they seem to me to be very stable (continuing the PowerShell team’s ability to ship rich, useful, and reliable beta code).

And even better, the PowerShell team seem to have gone back to their old roots in terms of time to market. They appear to be releasing as they develop (and long may this continue). Thus, the new SafeHarbor DSC resource, this was finished after Wave 5 was released but before Wave 6 was ready so the PowerShell team published it separately, then publish it (with updates and bug fixes) a few weeks later in the Wave 6 drop. I can’t tell you how good this feels after so long under the cone of silence.

This latest drop has some very interesting resources, including the xChrome and xFirefox resources that help to deploy these two browsers. The Group resource shipped with PowerShell 4 is updated to provide support for cross-domain account lookups as well as for UPN-formatted names. The new xRemoteDesktopAdmin resource enables. Additionally, Wave 6 has a number of bug fixes to earlier waves. Again – the ability to get these fixes quickly is both useful and much appreciated. 

The  DSC story is slowly coming clearer with both the July drop and these continuingly improving resources. And with Chef integrating with DSC, DSC’s future looks very rosy.  If you are looking to find out a bit more about DSC – I’ll be covering the basics on the PowerShell PowerCamp event in October.

Synchtoy–a free utility from Microsoft

I just stumbled across an interesting utility, called SyncToy. Version 2.1 of this tool is available, free, from Microsoft at: http://www.microsoft.com/en-us/download/details.aspx?id=15155. This is the latest version of this tool, which was first published in 2009, so it’s not really new.

This highly customisable tool synchronises files and folders between file locations, kind of like a robocopy designed just to synch your files between two locations. You could use this to sync files such as photos, music files etc. with other computers. This might be easier than worrying about backup for these files.

To find out more about Synchtoy, or to ask questions – see the synch toy forum at: http://social.microsoft.com/Forums/en-US/home?forum=synctoy.

del.icio.us Tags:

Tuesday, August 26, 2014

PowerShell V5 July 2014 Preview

As promised by Jeffrey Snover at TechEd US, Microsoft has released a new and updated pre-release version of PowerShell V5. Oddly, I can’t find too many references to it, but here is where you can get the preview:

Note that these versions only install on Windows 8.1 and Server 2012 R2. My main workstation runs Windows Server 2008 R2 and while I know it needs upgrading, I am dreading the upgrade. For now, I’m running this update on just my laptop. Sadly – as this update has a lot of new features.

The new features, described in more detail in the release notes, include:

  • Generation of Cmdlets based on an Odata Endpoint - Export-ODataEndpointProxy is a cmdlet that will generate a set of Windows PowerShell cmdlets based on the functionality exposed by a given OData Endpoint. This feature is still not quote complete as it’s still under development – but this looks a great idea to open up OData to wider use.
  • Manage .ZIP files with new cmdlets – finally two new cmdlets to manage zip files: Compress-Archive creates a new zip file while Expand-Archive allows un-zipping. At long last!
  • DSC authoring improvements in Windows PowerShell ISE. Several new features are added to the ISE to simplify authoring of DSC resources, including the ability to list all the DSC resources within a configuration block (use Ctrl+Space) and lots of improvements to autocomplete/tab complete.
  • Changes in how the DSC Local Configuration Manager is installed.
  • Partial DSC configurations – this, for me, was a missing piece to DSC. Partial DSC Configuration enables you to deliver configuration documents to a node in fragments. This is, for me, a great simplification in how you deploy DSC configurations.
  • Cross-Computer Synchronisation – this improves the built in WaitFor DSC resources. This is highly important for complex multi-node configuration scenarios where you need to sync several systems in order to properly configure them.
  • New DSC cmdlets – there are several new cmdlets, including Get-DSCConfigurationStatus, Compare-DNSConfiguration, Publish-DSCConfiguration and Update-DSCConfiguration.
  • The new Detailed Script Tracing feature enables detailed tracking and analysis of Windows PowerShell scripting use on a system. After you enable detailed script tracing, Windows PowerShell logs all script blocks to the ETW event log, Microsoft-Windows-PowerShell/Operational. If a script block creates another script block (for example, a script that calls the Invoke-Expression cmdlet on a string), that resulting script block is logged as well. I can see this being very, very useful!
  • The *-item cmdlets are extended to enable creation of symbolic links. Yet another cmd.exe feature now with PowerShell parity. YEAH!
  • And of course the latest WMF includes the cool features added to earlier versions, including OneGet, PowerShell Get, Network Switch management

PowerShell V5 is shaping up to be a pretty significant release, with a slew of really cool and, IMHO, important new features. I just hope there will be a version of PowerShell V5 for Windows 7/Server 2008 R2 so I can avoid the OS upgrade on my primary workstation.

Once I have this new update installed on my laptop, I’ll provide some additional feedback. I am looking forward already not only to playing with this new release, but in seeing what else Redmond and the PowerShell team have up their sleeves.

del.icio.us Tags: ,

Thursday, July 10, 2014

Satya Speaks–Towards a new Microsoft

I’ve been sitting in the garden, my Windows phone in my pocket, and browsing the web on my Surface RT. where I read with great interest Satya Nadella’s recent mail to Microsoft Employees. Microsoft kindly posted this email this morning at http://www.microsoft.com/en-us/news/ceo/index.html. Not only a smart move making the email before Mary Jo managed to get a leaked copy, but the contents are very exciting.

I opined a bit over a year ago that Microsoft needed new management. A view that did me no favors in parts of Redmond. The whole devices, phones and games vs. Azure vs. the ‘what keeps Microsoft afloat (Windows, Office, SQL, Exchange, Lync)’ was simply confusing. And the Cone Of Silence imposed by folks no longer at Microsoft was leading to a very closed culture which IMHO was not helpful for the customer.

But things have changed and that Cone of Silence seems to be a thing of the past. Jeffrey Snover noted at TechEd, The PowerShell team at least is back to working in Internet time as two new exciting builds of PowerShell V5 the team pumped out this year so far.

In July last year, Steve Ballmer set out a new direction, devices and services. That there was a new direction was a really good thing, as was Microsoft’s overarching goal of One Microsoft. And his departure and replacement with Satya was another major change. To me, he’s more than just a safe pair of hands!

But there was still confusion – why lead with the two areas Microsoft has been weak with (consider the relative success of Zune, Kin, Surface RT, BPOS, to name but a few) when the cash cows and technological leaders (Windows and Office) were put in a distant second place.  Satya notes that the ‘devices and services’ description was useful as a start, there is a need to hone on on a more detailed strategy (which is not so devices and services focused).

Today’s mail calls Microsoft ‘the productivity and platform company for the mobile-first and cloud-first world.’ To me this makes a log of sense and eliminates some of the confusion. It puts the platform in it’s place as just that, a platform. A platform to empower productivity. This approach seems to me to make a lot of sense. But as ever the devil is in the detail – Satya notes there is quite a lot of work to be done that will require nothing less than a complete transformation of Microsoft the company. That is a tall order, but the strategy sure seems sound.

The email also talks about the ‘Device OS.’ Which one is that going to be will be an interesting question for resolution. I personally love my Surface 1 RT. I use it daily as a device for consumption of content and some limited creation. Then there’s the Phone OS (I have Windows Phone 8.) It, too, has it’s moments. Finally, there is the traditional Windows as running on the Surface Pro and higher pc/server SKUs running on higher performance hardware. My use of traditional Windows is limited to my desktop and laptop, where I can type a whole lot faster than on the phone (and arguably more accurately). I think we have some interesting changes to the core product roadmap and I am looking forward to that being shared.

Microsoft is changing, and in a good way. The next couple of years is going to be very interesting. The Chinese curse: may you live in interesting times seems to have come home to roost! I look forward to the coming year.

del.icio.us Tags:

Monday, July 07, 2014

PowerShell PowerCamp–October 18-19th 2014

What is A PowerShell PowerCamp?
PowerCamp is a fast paced weekend training event that covers all the basic aspects of Windows PowerShell v5 - from the command line to writing production-oriented scripts and leveraging work flow and desired state configuration. We start with the basics including configuration, formatting and providers and remoting and jobs. Then, on day 2, we look at scripting, work flows, managing script libraries using modules, WMI/CIM,  using objects, and PowerShell in Windows. The event concludes with a look at the new Desired State Configuration feature in PowerShell 4 and 5.
The PowerCamp event is a combination of lecture, demonstrations plus Q&A, with the opportunity to type along with the tutor. There are no formal labs. But I do provide the key demos, all the slides, plus a wealth of other add on material on a memory stick you get at the start of day 1. So bring along your laptop, and type away.
What is the Agenda?
The event happens over the Weekend of October 18th and 19th. We start each day promptly at 9:00 and finish no later than 17:00.
Day 1 – The Basics
  • PowerShell Fundamentals – starting with the key elements of PowerShell (Cmdlets, Objects and the Pipeline) plus installation, setup, and profiles
  • What’s new in v5 – this looks at the things specifically added into PowerShell v5.
  • Formatting – how to format output nicely – both by default and using hash tables and display XML
  • Providers – getting into underlying OS data stores (certificate store, AD, registry, etc.) via providers
  • Remoting– working with remote systems using PowerShell’s remoting capabilities

Day 2 – Diving Deeper
  • Scripting Concepts – automating everyday tasks including PowerShell’s language constructs, error handling and debugging and workflows
  • Modules – managing PowerShell script libraries in the enterprise
  • Using .Net, COM, WMI and CIM objects – working with various kinds of objects
  • PowerShell in Windows – a look at what’s there and how you can leverage the huge number of cmdlets
  • PowerShell Desired State Configuration – this final module looks at PowerShell’s Desired State Configuration tool and what you can do with it.
What does it cost?
The cost is £200 (+VAT at the prevailing rate) for the weekend. Meals and accommodation are not covered.
Where is the event going to take place?
The PowerShell PowerCamp is being held at Microsoft Cardinal Place, 100 Victoria Street in Victoria. We will hold it on the weekend of October 18/19 2014. Each day starts promptly at 09:00 and finishes up by 16:45. We’ll also take short break throughout the day, including a 1-hour lunch break
PowerDrinks? After Saturday’s session, attendees are invited to a small nearby public house for some lovely English ale and networking with each other!
Who is the tutor?
The PowerShell Weekend PowerCamp is delivered by Thomas Lee. Thomas has been involved in the PowerShell community since the very beginning. He provides training and consultancy around a range of Microsoft products, with a recent focus on PowerShell and Lync Server. Thomas runs PowerShell training courses around the world, and has been a speaker at conferences across the world for the past decade. In his spare time, he lives with his wife, daughter, wine cellar, and Grateful Dead live recordings archive in a small cottage in the English countryside. His Twitter handle is @DoctorDNS and he maintains two blogs (Under the Stairs at http://tfl09.blogspot.com and PowerShell Scripts Blog at http://pshscripts.blogspot.com).
What do I need to bring?
You need to bring a laptop with PowerShell v5 loaded. That can be either native or in a virtual machine. I suggest you have at least two VMs pre-configured – one a server 2012 R2 installation the other a Windows 8 ,1installation. The virtualisation software is not of concern – but you need 64-bit guest OS support for Server 2012! Thus you can use Hyper-V, VMware Workstation or Oracle’s Virtual Box. Heck, run it in a VM on a Mac or Linux PC if you want. Just bring along PowerShell v3/4/5 (preferably V5!).
How do I book?
Contact DoctorDNS@Gmail.com to book a place and to arrange for the invoice to be paid. Payment must be in cash, cheque or bank transfer – I don’t take credit cards.
More Details
Watch this blog for any hot breaking news on the event.

Tuesday, July 01, 2014

PowerShell ISE Keyboard Shortcuts

I hit a recent issue using the ISE and trying to use the updated version of James Brundage’s ISEPackv2 module – a keyboard shortcut used in James’s module has been taken by a later version of PowerShell. Not the end of the world and easily remedied (heck, I have the code!). I was playing around with keyboard shortcuts and wrote a little function that, when run inside the ISE, gets the keyboard shortcuts that are set.
I’ve published the Get-ISEShortcut over on my PowerShell scripts blog, but the core of function is these lines of code:
$gps = $psISE.GetType().Assembly
$rm = New-Object System.Resources.ResourceManager GuiStrings,$gps
$rm.GetResourceSet((Get-Culture),$True,$True) |
    Where Value -CMatch "(F\d)|(Shift\+)|(Alt\+)|(Ctrl\+)"
This code gets the GUI related resource strings held by the ISE and then weeds out all but he keyboard shortcuts. In the published script, I sort them to get a more effective list. On my system, I get the following:
PSH [C:\foo]: Get-ISEShortcut | ft -AutoSize value, name
Value               Name                                          
-----               ----                                          
Alt+Backspace       EditorUndoShortcut2                           
Alt+Down            EditorSelectNextSiblingShortcut               
Alt+F4              ExitShortcut                                  
Alt+Left            EditorSelectEnclosingShortcut                 
Alt+Right           EditorSelectFirstChildShortcut                
Alt+Shift+Backspace EditorRedoShortcut2                           
Alt+Shift+Down      EditorBoxSelectLineDownShortcut               
Alt+Shift+H         ToggleHorizontalAddOnPaneShortcut             
Alt+Shift+Left      EditorBoxSelectToPreviousCharacterShortcut    
Alt+Shift+Right     EditorBoxSelectToNextCharacterShortcut        
Alt+Shift+T         EditorTransposeLineShortcut                   
Alt+Shift+Up        EditorBoxSelectLineUpShortcut                 
Alt+Shift+V         ToggleVerticalAddOnPaneShortcut               
Alt+Up              EditorSelectPreviousSiblingShortcut           
Ctrl+1              ShowScriptPaneTopShortcut                     
Ctrl+2              ShowScriptPaneRightShortcut                   
Ctrl+3              ShowScriptPaneMaximizedShortcut               
Ctrl+A              EditorSelectAllShortcut                       
Ctrl+Add            ZoomIn1Shortcut                               
Ctrl+Alt+End        EditorMoveCurrentLineToBottomShortcut         
Ctrl+Alt+Home       EditorMoveCurrentLineToTopShortcut            
Ctrl+B              BreakAllDebuggerShortcut                      
Ctrl+Backspace      EditorDeleteWordToLeftShortcut                
Ctrl+Break          StopExecutionShortcut                         
Ctrl+C              StopAndCopyShortcut                           
Ctrl+D              GoToConsoleShortcut                           
Ctrl+Del            EditorDeleteWordToRightShortcut               
Ctrl+Down           EditorScrollDownAndMoveCaretIfNecessaryShortcut
Ctrl+End            EditorMoveToEndOfDocumentShortcut             
Ctrl+F              FindShortcut                                  
Ctrl+F1             ShowCommandShortcut                           
Ctrl+F4             CloseScriptShortcut                           
Ctrl+G              GoToLineShortcut                              
Ctrl+H              ReplaceShortcut                               
Ctrl+Home           EditorMoveToStartOfDocumentShortcut           
Ctrl+I              GoToEditorShortcut                            
Ctrl+Ins            Copy2Shortcut                                 
Ctrl+J              ShowSnippetShortcut                           
Ctrl+Left           EditorMoveToPreviousWordShortcut              
Ctrl+M              ToggleOutliningExpansionShortcut              
Ctrl+Minus          ZoomOut3Shortcut                              
Ctrl+N              NewScriptShortcut                             
Ctrl+O              OpenScriptShortcut                            
Ctrl+Oem6           GoToMatchShortcut                             
Ctrl+Plus           ZoomIn3Shortcut                               
Ctrl+R              ToggleScriptPaneShortcut                      
Ctrl+Right          EditorMoveToNextWordShortcut                  
Ctrl+S              SaveScriptShortcut                            
Ctrl+Shift+Add      ZoomIn2Shortcut                               
Ctrl+Shift+D        GetCallStackShortcut                          
Ctrl+Shift+End      EditorSelectToEndOfDocumentShortcut           
Ctrl+Shift+F9       RemoveAllBreakpointsShortcut                  
Ctrl+Shift+H        HideHorizontalAddOnToolShortcut               
Ctrl+Shift+Home     EditorSelectToStartOfDocumentShortcut         
Ctrl+Shift+L        ListBreakpointsShortcut                       
Ctrl+Shift+Left     EditorSelectToPreviousWordShortcut            
Ctrl+Shift+Minus    ZoomOut4Shortcut                              
Ctrl+Shift+P        StartPowerShellShortcut                       
Ctrl+Shift+Plus     ZoomIn4Shortcut                               
Ctrl+Shift+R        NewRemotePowerShellTabShortcut                
Ctrl+Shift+Right    EditorSelectToNextWordShortcut                
Ctrl+Shift+Subtract ZoomOut2Shortcut                              
Ctrl+Shift+U        EditorMakeUppercaseShortcut                   
Ctrl+Shift+V        HideVerticalAddOnToolShortcut                 
Ctrl+Space          IntellisenseShortcut                          
Ctrl+Subtract       ZoomOut1Shortcut                              
Ctrl+T              NewRunspaceShortcut                           
Ctrl+U              EditorMakeLowercaseShortcut                   
Ctrl+Up             EditorScrollUpAndMoveCaretIfNecessaryShortcut 
Ctrl+V              Paste1Shortcut                                
Ctrl+W              CloseRunspaceShortcut                         
Ctrl+X              Cut1Shortcut                                  
Ctrl+Y              EditorRedoShortcut1                           
Ctrl+Z              EditorUndoShortcut1                           
F1                  F1KeyboardDisplayName                         
F1                  HelpShortcut                                  
F10                 StepOverShortcut                              
F10                 F10KeyboardDisplayName                        
F11                 StepIntoShortcut                              
F11                 F11KeyboardDisplayName                        
F12                 F12KeyboardDisplayName                        
F2                  F2KeyboardDisplayName                         
F3                  F3KeyboardDisplayName                         
F3                  FindNextShortcut                              
F4                  F4KeyboardDisplayName                         
F5                  F5KeyboardDisplayName                         
F5                  RunScriptShortcut                             
F6                  F6KeyboardDisplayName                         
F7                  F7KeyboardDisplayName                         
F8                  F8KeyboardDisplayName                         
F8                  RunSelectionShortcut                          
F9                  F9KeyboardDisplayName                         
F9                  ToggleBreakpointShortcut                      
Shift+Backspace     EditorDeleteCharacterToLeftShortcut           
Shift+Del           Cut2Shortcut                                  
Shift+Down          EditorSelectLineDownShortcut                  
Shift+End           EditorSelectToEndOfLineShortcut               
Shift+Enter         EditorInsertNewLineShortcut                   
Shift+F11           StepOutShortcut                               
Shift+F3            FindPreviousShortcut                          
Shift+F5            StopDebuggerShortcut                          
Shift+Home          EditorSelectToStartOfLineShortcut             
Shift+Ins           Paste2Shortcut                                
Shift+Left          EditorSelectToPreviousCharacterShortcut       
Shift+PgDn          EditorSelectPageDownShortcut                  
Shift+PgUp          EditorSelectPageUpShortcut                    
Shift+Right         EditorSelectToNextCharacterShortcut           
Shift+Up            EditorSelectLineUpShortcut