One point in the “small print” is important to note. This is the last release of these resource as a big zip file for download from the TechNet script gallery. In future these resources will only be available through the PowerShell gallery. Use Find-DscResource to discover the resources available in the gallery and Update-Module & Install-module to get the modules containing resources from the gallery.

A question came up on the forum about copying files with CIM (WMI). I normally use Copy-Item rather than CIM as its easier. The questioner was using CIM_LogicalFile when I’ve normally used CIM_DataFile so I decided to take a look at the class. In reality the two classes are very similar and CIM-datafile could be substituted for CIM_LogicalFile in the code that follows.

The obvious starting point is to use the Copy method on the CIM_LogicalFile class

Couple of points to note. In the Path part of the filter you have to escape the \ delimiter. Extension doesn’t include the ‘.’

You have to give the full path – including file name – to the loaction to which you want to copy the file. In this case you don’t have to escape the \ delimiter. Consistency is a wonderful thing and usually absent from WMI.

My test lab is a set of virtual machines running on a Lenovo w1510 laptop. When I’ve finished working for the day I want to shut down the virtual machines and the laptop. I may have anywhere between 2 and 8 (or more) VMs running so scripting the shutdown helps a lot.

Machines can be shutdown independently so this is an action that is ideal for parallel execution through a workflow.

I use WSUS in my lab to update machines – means I only have to download updates once. The issue is that I have to start the VMs so they can communicate with the WSUS server. WSUS will start to flag warnings if machines haven’t contacted the WSUS server for more than that length of time.

Putting that together I can use the UpdateServices (WSUS) module and the Hyper-V module to start machines that have been turn off more than 7 days.

Use get-WsusComputer to pull the machine names. I filter on W12R2 (all my machine names contain an abbreviated OS type) and check the last status report time.

Any machines that haven’t reported – the VM data is retrieved and if the machine isn’t running it’s started. Machines take about 25-30 seconds to boot on my lab so a sleep of 30 seconds means I’m not starting them all at once.

About This Blog

A blog for Windows administrators, Architects, Consultants and System Integrators maximizing the use of PowerShell and WMI. Simple solutions to everyday problems using two tools that should be available on every Windows system. Save time, save effort, script now!