The resource kit contains a module with 8 DSC Resources for managing domain membership, websites, Hyper-V VMs, VHDs, switches and so on. The resources is prefixed with “x” – where the “x” stands for experimental, meaning these resources are provided “as is” and are not supported through any Microsoft support program or service. It is also stated that anyone can adapt the resources, but it is suggested to rename them with your own naming convention like Contoso_cWebsite.
I just finished reading The Phoenix Project: A Novel About IT, DevOps, and Helping Your Business Win:
The story is about Bill Palmer, an IT Manager at a company called Parts Unlimited. The company is considering outsourcing IT or splitting up the company, due to many failures in operations and projects. The competitors has launched new and innovative services, while Parts Unlimited stays behind and loses customers. The company initiates a new IT project code named The Phoenix Project in order to catch up with the market and save the company. During the book common scenarios in many IT departments` everyday life is observed such as much firefighting and not being able to keep up with projects. As often before, internal IT projects which would have mitigated many of the problems is not prioritized. Getting more people is not an option according to the CEO, and would unlikely resolve the issues as we learn during the story. We learn how to think about IT, how cloud computing can be leveraged, as well as the importance of practices like ITIL and interdepartmental communications such as between developers and operations. Many times during the book I thought of how this relates to Windows PowerShell in terms of being able to automate manual repetitive work, as well as having consistent procedures for operations such as deployments. Specifically, technologies such as PowerShell Workflow and Desired State Configuration is coming to mind when I`m thinking about how to solve many of the challenges.
I would highly recommend this book to anyone who will be working with IT in the coming years, it really is an eye-opener. No matter what your role in IT is, I think you will learn something which can help you and your business going forward.
The 2014 Winter Scripting Games, beginning in the middle of January, gives you the opportunity to test your Windows PowerShell skills and get feedback from Subject Matter Experts. New this time is the ability to form teams and collaborate on the given challenges, which in practice will simulate a real world scenario where you collaborate with your colleagues. Each team will need to have at least 2 persons. There will be judges for scoring the events as well as coaches offering comments and advice to the teams. Personally I will be contributing to the games as a coach, which I`m really looking forward to. I will also write articles on my blog giving advice on my observations during the games. If you want to participate, be sure to read the 2014 Winter SG Players Guide.
You can find more information in the following articles over at powershell.org:
For those of you based in Norway I would also be very happy if you would like to join our local MTUG Script Club team for the games, you can find for information here. There will also be a practice event available starting to accept entries on January 6th.
On January 1st I got an e-mail from Microsoft stating that I am renewed as a PowerShell MVP for another year:
Dear Jan Egil Ring, Congratulations! We are pleased to present you with the 2014 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in PowerShell technical communities during the past year.
This is the 4th time I receive this award, and I am very honored and privileged to be part of this amazing community. Windows PowerShell 4.0 was released last year as part of Windows 8.1 and Windows Server 2012 R2, with a very broad PowerShell coverage. New features such as Desired State Configuration opens up for even more possibilities. I`m looking forward to contribute and interact with the PowerShell community in 2014, as we see that PowerShell and automation in general is becoming more and more important.
Introduced in PowerShell 3.0 and further enhanced in PowerShell 4.0, the CIM (Common Information Model) Cmdlets makes it easier to work with WMI (Windows Management Instrumentation). You can find an introduction to the new CIM Cmdlets in this article on the Windows PowerShell Team`s blog.
In this article we will look at a usage scenario for the new CIM Cmdlets.
When adding a disk to a Windows Failover Cluster, the clustered disk is added to the cluster as a resource. The resource is automatically named “Cluster Disk N”, where N is the first available number. The challenge we are going to solve is renaming the newly added cluster disk based on the name (File System Label) of the underlying disk volume. This is typically an NTFS volume which is initialized and formatted before the disk is added to the cluster:
Using the Failover Cluster Manager in Windows Server we can view the name of the underlying volume:
Based on this observation we can manually rename the cluster resource. However, in a large cluster with many disks this task is a good candidate for automation.
Solving the challenge using CIM Cmdlets
By using the Get-ClusterResource cmdlet in the FailoverClusters PowerShell module we can view information about the disk, but there isn`t an easy way to view the name of the underlying volume.
Due to that, we can rather leverage the Get-CimInstance cmdlet to list all cluster resources in the MSCluster_Resource class:
We use the –Filter parameter to specify that we only want cluster resources of the type “Physical Disk”, if not we would also get cluster resources such as cluster IP addresses, cluster names and so on.
Based on the information available on the object produced by Get-CimInstance, we can see many cluster related properties. However, no information about the underlying volume is available.
There is one cmdlet in the CIMCmdlets module which can get all the associated instances for a particular instance – the Get-CimAssociatedInstance cmdlet. In this scenario, we want to find all related volumes for the cluster disks. We start by finding all related instances:
This produced a large list of different kind of objects. We can use Get-Member to view information about the objects, and Select-Object to view the unique object types:
Based on the above output, the MSCluster_DiskPartition looks like a good candidate. We can use the –ResultClass parameter of Get-CimAssociatedInstance in order to narrow down the results to the class we want:
This is excactly what we want, as we can see the VolumeLabel property on the above output.
Now that we have the information we want – the VolumeLabel property – we need to find a way to rename the cluster resource (“Cluster Disk 1”). We can start by looking for a Rename method on the MSCluster_DiskPartition object. Normally, we would use Get-Member to view the available methods:
Since the CIM cmdlets is using the Ws-Man (WS-Management) protocol, the objects we get returned is serialized/deserialized. Thus the object`s methods is remove since we aren`t working with a “live” object. The Get-CimClass cmdlet can be used to get the class schema of a CIM class, which includes the methods.
Instead let`s try the Get-CimClass cmdlet to view the methods available on the mscluster_resource class:
As we can see, there is a Rename method which takes one parameter: newName.
In order to invoke the method, we can use the Invoke-CimMethod cmdlet where we specify Rename as the MethodName and provide the value we want to configure as a hash table on the Arguments parameter:
We provided the VolumeLabel property returned by the Get-CimAssociatedInstance cmdlet as the value for the newName parameter, effectively solving the challenge.
After invoking the method, we can see the name of the cluster disk is immediately updated in Failover Cluster Manager:
When working with multiple cluster disks, we can use a foreach loop in order to invoke the rename method for all disks if the name of the cluster resource does not match the name of the underlying disk volume:
Verify that all prerequisites is installed according to the Windows Management Framework 4.0 supportability matrix above. To verify the presence of .NET 4.5, you may use the Test-Net45 function available in this article on the Hey Scripting Guy! Blog
Run the installation file applicable to the operating system
Reboot the computer, start Windows PowerShell and verify that the output of $PSVersionTable shows 4.0 as the value of the PSVersion property
1 – Installation succeeds even if .NET 4.5 is not installed
Scenario: Installing WMF 4.0 on a computer that is not running .NET Framework 4.5 will report that the installation is successful, but the components of WMF 4.0 (such as Windows PowerShell, WMI, etc.) will not be updated.
Solution: Install .NET Framework 4.5, and then run the WMF 4.0 installer again.
Update is available that prevents the PSModulePath environment variable from being reset when you upgrade WMF 3.0 to WMF 4.0 and then uninstall WMF 4.0 in Windows: http://support.microsoft.com/kb/2872047
What I want to show in this article is a challenge when working with the Get-PrinterDriver cmdlet, related to version info.
Let us have a look at the default output:
With an IT Professional`s mindset, the MajorVersion property shown in the default output would probably be the printer driver`s driver version, right?
Let us have a look at the same printer drivers using the Print Management MMC Console:
If we compare the two outputs, an educated guess would tell us that the MajorVersion property in the output of Get-PrinterDriver is actually the driver type (for example “Type 3 – User Mode”).
So how can we get the “Driver Version” property in the Print Management MMC Console in PowerShell? Let us use Get-Member to explore what properties is available on an object produced by Get-PrinterDriver:
It seems like the property “DriverVersion” is what we want, let us try:
This does not look very promising. The data we want is there, but not in a human readable format. The data is in an uint64 format, and would need to be converted in order to see the same values as we get in the Print Management MMC Console.
We can find an explanation on how the data is represented in this article on MSDN:
By using Select-Object we can convert the DriverProperty value into the same format as the Print Management MMC Console:
Thanks to PowerShell MVP Keith Hill for assisting with the conversion process.
I have also filed a suggestion on Microsoft Connect suggesting that more user friendly driver version information should be available by default on the objects created by the Get-PrinterDriver cmdlet.
If you find the need to provide feedback to Microsoft, whether it is bug reports or feature suggestions, you can find more information on how to do this in a previous article I have written.
Microsoft Lync is the client for Microsoft`s unified communications platform Lync Server. The Lync client API includes the Microsoft Lync Model API and the Microsoft Lync Extensibility API, which is primarily targeted at developers who are building custom Lync applications or integrations with Line-Of-Business applications. The API is available in the Lync SDK (Software Developer Kit), the SDK for the latest version for the Lync client is available here. Since the SDK is .NET it is possible to leverage Windows PowerShell to access it. When the SDK is installed, you simply import the assembly Microsoft.Lync.Model.dll as a binary module using Import-Module:
In order to have a practical task to solve, I decided to try to configure the availability for the Lync client. Typically I want to configure my availability to “Available” when I get to work in the morning, and “Off Work” when I leave at the end of the day (my work computer is always powered on). I often forget to change the status, so I decided to use the new Scheduled Jobs functionality introduced in Windows PowerShell 3.0 in order to schedule the configuration of my Lync availability.
I have created a PowerShell function, Publish-LyncContactInformation, which makes it possible to configure Lync availability, location and personal note:
For the Availability parameter, the ValidateSet parameter validation attribute is used to validate the supplied parameters. This also gives us Intellisense in the PowerShell ISE:
Availability is provided with integer values, the possible values is available here. To make it more user friendly a switch statement is used to map the string values to the correct integer value, this makes it possible for the user to supply “Available” instead of “3000” as the parameter value.
What I could not find a value for was the “Off Work” status. It turns out that the Activity Id also must be configured in order to set availability to “Off Work” (thanks to Jens Trier Rasmussen for helping me with this one), more info here. Example usage: Publish-LyncContactInformation -Availability “Off Work” -ActivityId off-work
There are a number of presence items which can be configured, you can find more info here. In addition to the Availability and Activity Id I also included Personal Note and Location as parameters. It is also possible to add more items if needed, for example Photo URL.
Several examples on how to use the function is included in the help, run Get-Help Publish-LyncContactInformation –Examples to view them:
In example 5, a function is used to set the personal note in Lync. You can find the function here. After running the command in example 5, my Lync client presence looked like this:
Using Register-ScheduledJob, I have configured the function to run at 8.00 in the morning and 16.00 in the afternoon:
You can find an example on how to schedule the Publish-LyncContactInformation function here.
There are a couple of gotchas I would like to mention at the end:
#1: When using Register-ScheduledJob, the task created in \Microsoft\Windows\PowerShell\ScheduledJobs in the Task Scheduler is configured with the option “Run whether the user is logged on or not”. In order for [Microsoft.Lync.Model.LyncClient]::GetClient() to work properly from the scheduled job, the option must be set to “Run only when user is logged on”:
I have not found any way to configure this option using the cmdlets in the PSScheduledJobs module, so I configured this manually from the Task Scheduler. I will update this article when I have more information.
Update 2013-08-09:Using the Set-ScheduledTask cmdlet from the ScheduledTasks module works fine:
NOTE: You can view and manage Windows PowerShell scheduled jobs in Task Scheduler, but the Windows PowerShell job and Scheduled Job cmdlets work only on scheduled jobs that are created in Windows PowerShell.
Based on this, my understanding is that modifying a scheduled task created by Register-ScheduledJob using Set-ScheduledTask is supported.
#2: When running the Lync SDK setup file I encountered the following error:
In order to avoid having to install Visual Studio, extract the exe-file using for example 7-Zip. Then you can install the Lync SDK by running the MSI-file from the extracted folder.
Get-CommandGridView is a PowerShell function written by PowerShell MVP Jeffery Hicks, which he blogged about here. I think this is a nice way to explore what is available in PowerShell modules and snapins. The function will show the available cmdlets in the specified module or snapin in a grid window, showing the properties Name,Noun,Verb,CommandType and ModuleName:
I think this is a great way to explore new modules/snapins, but I also thought it would be a good idea to leverage the new –PassThru switch on Out-GridView introduced in PowerShell 3.0 to let the user select commands to be sent to Get-Help –ShowWindow to further explore the help for interesting cmdlets/functions. I modified Jeff`s original function to provide this functionality:
Here is an example from running Get-CommandGridView -Module Hyper-V:
You can now select one or more cmdlets (using Shift or Ctrl + select) and then hit the OK button to bring up help windows for the selected cmdlets:
If no module is specified, all cmdlets and functions will be retrieved. That could potentially be thousands of cmdlets/functions, so in order to protect the user from opening to many help windows I added a validation attributte to the MaxHelpWindowCount parameter.
The functionality of the Get-CommandGridView function is similar to the Show Command Add-on introduced in PowerShell ISE 3.0, but I think it is more convenient when exploring new modules.
Here is a screenshot of the Show Command Add-on for those who have not seen it:
Windows PowerShell is software, and software in general will always have bugs as well as needs for new features and improvements. Microsoft has a feedback channel called Microsoft Connect where customers can report bugs and provide suggestions for feedback to their software. There is a dedicated Connect website for Windows PowerShell, connect.microsoft.com/PowerShell:
Many of the changes since Windows PowerShell 1.0 is based upon feedback from customers. To help Microsoft prioritize what is important for customers, there is a voting available for each submission:
There are also dedicated Connect programs for other Microsoft software, which you can find browsing the Connect Directory.
Personally, I have submitted 3 feature suggestions recently. While I was evaluating the new Desired State Configuration (DSC) feature in Windows PowerShell 4.0 in my lab environment, I experienced need for features which was not available they way I would like. For example, the DSC feature provides logging to Windows event logs (ETW), and I would find it very useful to be able to retrieve new items from these event logs in a PowerShell session as they arrive. You can find more information about this suggestion as well as the other two I recently submitted on the respective Connect submissions:
Using the Connect feedback channel provides you a way to possible affect new features in the product, and helps Microsoft understand what features the customers want.
Another feedback opportunity you should know about Windows PowerShell is regarding to the help system. Since version 3, the help system is updateable (Update-Help), which makes it possible for Microsoft to update the help files with more information as well as correcting errors on a regular basis. To report errors or suggestions for the help system, you can use the e-mail alias firstname.lastname@example.org. PowerShell MVP Thomas Lee has written a blog post where you can find more information.