Spent the past hour and half attending this course – Getting started with PowerShell Desired State Configuration (DSC) Jump Start, by Jeffrey Snover (inventor of PowerShell) and Jason Helmick. Had to give up coz my connection quality is so poor it kept freezing every now and then. Better to wait 2-3 weeks for the recorded version to be released so I can download and view. It’s a pity I couldn’t watch this though. I was looking forward to this course very much (and also its sequel Advanced PowerShell Desired State Configuration (DSC) and Custom Resources same time tomm which I will now have to skip).
From the little bit that I did attend, here are some notes.
Desired State Configuration (DSC)
- Desired State Configuration (DSC) is meant to be a platform. You have tools that can manage configuration changes. And you have the actual items which you configure. Usually the tools are written specifically for the item you wish to configure. So, a certain tool might be good at managing certain aspects of your environment but not that great at managing other aspects. What Microsoft’s goal here is to offer a platform for configuration tools. Jeffrey likens it to Word Processors and printers in the past. Whereas once upon a time Word Processors were tied to printers in that certain Word Processors only worked with certain printers, once Windows OS came along and it had the concept of print drivers, all that was required was for printer manufacturers to provide drivers for their model and Word Processors to target this driver model and soon all Word Processors could print to all printers. DSC has a similar aim.
- DSC tends to get compared to GPOs a lot because they do similar things. But, (1) GPOs require domain joined machines – which DSC does not require – and (2) with a GPO you don’t have a way of knowing whether the policy applied successfully and/ or what failed, while with DSC you have insight into that. Other differences are that GPOs are tied to Windows whereas DSC is standards based so works with Linux and *nix (and even network switches!).
- DSC is Distributed & Heterogeneous. Meaning it’s meant to scale across a large number of devices or various types.
- Local Configuration Manager (LCM) is a WMI agent that’s built into PowerShell 4 and above. It is the engine behind DSC? (The presenters were starting to explain LCM in Module 2 which is when I finally gave up coz of the jerkiness).
- Windows Management Infrastructure (WMI) has an open source counterpart (created by Microsoft?) called Open Management Infrastructure (OMI) for Linux and *nix machines. This is based on DMTF standards and protocols. Since LCM is based on WMI whose open source counterpart is OMI, LCM can work with Linux and *nix machines too.
- DevOps model is the future. Release a minimal viable product (i.e. release a product that works with the minimum requirements and then quickly keep releasing improvements to it). Respect reality (i.e. release what you have in mind, collect customer feedback (reality), improve the product). Jeffrey Snover recommends The Phoenix Project, a novel on the DevOps style.
- Windows Management Framework (WMF) – which contains PowerShell, WMI, etc – now follows a DevOps style. New releases happen every few months in order to get feedback.
OneGet and friends
- NuGet is a package manager for Visual Studio (and other Windows development platforms?). Developers use it to pull in development libraries. It is similar to the package managers for Perl, Ruby, Python, etc. I think.
- Chocolatey is a binary package manager, built on NuGet infrastructure, but for Windows. It is similar to
apt-get
,yum
, etc. Chocolatey is what you would use as an end-user to install Chrome, for instance. - OneGet is a package manager’s manager. It exposes APIs for package managers (such as Chocolatey) to tap into, as well as APIs for packages to utilize. OneGet is available in Windows 10 Technical Preview as well as in the WMF 5.0 Preview. Here’s the blog post introducing OneGet. Basically, you can use a set of common cmdlets to install/ uninstall packages, add/ remove/ query package repositories regardless of the installation technology.
To my mind, an analogy would be that OneGet is something that can work with deb
and rpm
repositories (as well as repositories maintained by multiple entities such as say Ubuntu deb
repositories, Debian deb
repositories) and as long as these repositories have a hook into OneGet. You, the end user, can then add repositories containing such packages and use a common set of cmdlets to manage it. This is my understanding, I could be way off track here …
Installing WMF 5.0 preview on my Windows 8.1 machine, for instance, gets me a new module called OneGet
. Here are the commands available to it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
PS> Get-Command -Module OneGet CommandType Name Version Source ----------- ---- ------- ------ Cmdlet Find-Package 1.0.0.0 OneGet Cmdlet Get-Package 1.0.0.0 OneGet Cmdlet Get-PackageProvider 1.0.0.0 OneGet Cmdlet Get-PackageSource 1.0.0.0 OneGet Cmdlet Install-Package 1.0.0.0 OneGet Cmdlet Register-PackageSource 1.0.0.0 OneGet Cmdlet Save-Package 1.0.0.0 OneGet Cmdlet Set-PackageSource 1.0.0.0 OneGet Cmdlet Uninstall-Package 1.0.0.0 OneGet Cmdlet Unregister-PackageSource 1.0.0.0 OneGet |
As part of the course Jeffrey mentioned the PowerShell Gallery which is a repository of PowerShell and DSC stuff. He mentioned two modules – MVA_DSC_2015_DAY1
and MVA_DSC_2015_DAY2
– which would be worth installing to practice what is taught during the course. The PowerShell Gallery has its own package manager called PowerShellGet
which has its own set of cmdlets.
1 2 3 4 5 6 7 8 9 10 11 12 |
PS> Get-Command -Module PowerShellGet CommandType Name Version Source ----------- ---- ------- ------ Function Find-Module 0.5 PowerShellGet Function Get-PSRepository 0.5 PowerShellGet Function Install-Module 0.5 PowerShellGet Function Publish-Module 0.5 PowerShellGet Function Register-PSRepository 0.5 PowerShellGet Function Set-PSRepository 0.5 PowerShellGet Function Unregister-PSRepository 0.5 PowerShellGet Function Update-Module 0.5 PowerShellGet |
Notice there are cmdlets to find modules, install modules, and even publish modules to the repository. One way of installing modules from PowerShell Gallery would be to use the PowerShellGet
cmdlets.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
PS> Find-Module mva* NuGet-anycpu.exe is required to continue. PowerShellGet requires NuGet-anycpu.exe to interact with NuGet based galleries. NuGet-anycpu.exe must be available in 'C:\Program Files\OneGet\ProviderAssemblies' or 'C:\Users\Rakhesh\AppData\Local\OneGet\ProviderAssemblies'. For more information about NuGet provider, see http://oneget.org/NuGet.html. Do you want PowerShellGet to download NuGet-anycpu.exe now? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Version Name Repository Description ------- ---- ---------- ----------- 0.0.0.2 MVA_DSC_2015_DAY1 PSGallery This contains the presentations and modules asso... 0.0.0.2 MVA_DSC_2015_DAY2 PSGallery This contains the presentations and modules asso... |
Notice that it depends on NuGet to proceed. My guess is that NuGet is where the actual dependency resolution and other logic happens. I can install the modules using another cmdlet from PowerShellGet
:
1 2 3 4 5 6 7 8 9 10 11 |
PS> Find-Module mva* | Install-Module You are installing the module 'MVA_DSC_2015_DAY1' from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install software from 'https://www.powershellgallery.com/api/v2/'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y You are installing the module 'MVA_DSC_2015_DAY2' from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install software from 'https://www.powershellgallery.com/api/v2/'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): |
Now, the interesting thing is that you can do these operations via OneGet
too. Because remember, OneGet
provides a common set of cmdlets for all these operations. You use the OneGet
provided cmdlets and behind the scenes it will get the actual providers (like PowerShellGet
) to do the work. (Update: Turns out it’s actually the reverse. Sort of. Install-Module
from PowerShellGet
actually invokes Install-Package -Provider PSModule
from OneGet
. This works because PowerShellGet
hooks into OneGet
with so OneGet
knows how to use the PowerShellGet
repository).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
PS> Find-Module *fire* Version Name Repository Description ------- ---- ---------- ----------- 1.0.0 xFirefox PSGallery Firefox Main module PS> Find-Package *fire* Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- xFirefox 1.0.0 Available PSModule https://www.p... PS> Find-Package *fire* | Install-Package The package 'xFirefox' comes from a package source that is not marked as trusted. Are you sure you want to install software from 'https://www.powershellgallery.com/api/v2/'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- xFirefox 1.0.0 Installed PSModule https://www.p... |
Remember, the find-*
cmdlets are for searching the remote repository. The get-*
cmdlets are for searching the installed packages. PowerShellGet
is about modules, hence these cmdlets have the noun as module
. OneGet
is about packages (generic), so the noun has package
.
Very oddly, there seems to be no way to uninstall the modules installed from the PowerShell Gallery. As you can see below Uninstall-Module
does nothing. That’s because there’s no uninstall cmdlet from PowerShellGet
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS> get-package *fire* | Uninstall-Package PS> get-package *fire* Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- xFirefox 1.0.0 Installed PSModule https://www.p... Firefox Main module PS> Get-Command -Module PowerShellGet CommandType Name Version Source ----------- ---- ------- ------ Function Find-Module 0.5 PowerShellGet Function Get-PSRepository 0.5 PowerShellGet Function Install-Module 0.5 PowerShellGet Function Publish-Module 0.5 PowerShellGet Function Register-PSRepository 0.5 PowerShellGet Function Set-PSRepository 0.5 PowerShellGet Function Unregister-PSRepository 0.5 PowerShellGet Function Update-Module 0.5 PowerShellGet |
I installed the xFirefox
module above. Again, from the course I learnt that “x” stands for experimental. To know more about this module one can visit the page on PowerShell Gallery and from there go to the actual module DSC resource page. (I have no idea what I can do with this module. From the module page I understand it should now appear as a DSC resource, but when I do a Get-DSCResource
it does not appear. Tried this for the xChrome
module too – same result. Other modules, e.g. xComputer
, appear fine so it seems to be an issue with the xFirefox
and xChrome
modules.)
Notice I have two repositories/ sources on my system now: Chocolatey, which came by default, and PowerShell Gallery. I can search for packages available in either repository.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
PS> Get-PackageSource Name ProviderName IsTrusted IsRegistered IsValidated Location ---- ------------ --------- ------------ ----------- -------- chocolatey Chocolatey False True False http://chocolatey.org/api/v2/ PSGallery PSModule False True False https://www.powershellgallery... PS> Find-Package -ProviderName Chocolatey Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- foxe.install 2.4.2.2 Available Chocolatey chocolatey suricata 2.0.2.201... Available Chocolatey chocolatey Free open-source IDS/IPS/N... xmlstarlet 1.6.1 Available Chocolatey chocolatey foxe 2.4.2.2 Available Chocolatey chocolatey processhacker.portable 2.33.0 Available Chocolatey chocolatey processhacker 2.33.0 Available Chocolatey chocolatey foxe.portable 2.4.2.2 Available Chocolatey chocolatey flashdevelop 4.7.1 Available Chocolatey chocolatey Open source code editor fo... ffdshow-x86_32 1.3.4531 Available Chocolatey chocolatey The all-in-one codec solution |
OneGet
is working with Chocolatey developers to make this happen. Currently OneGet
ships with a prototype plugin for Chocolatey, which work with packages from the Chocolatey repository (note: this plugin is a rewrite, not a wrapper around the original Chocolatey). For instance, here’s how I install Firefox from Chocolatey:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PS> Find-Package -Name *firefox* Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- adblockplusfirefox 0.0.0.1 Available Chocolatey chocolatey Firefox 35.0.1 Available Chocolatey chocolatey Bringing together all kind... FirefoxESR 31.2.0 Available Chocolatey chocolatey This package installs Fire... xFirefox 1.0.0 Available PSModule https://www.p... PS> Install-Package -Name Firefox -ProviderName Chocolatey The package 'Firefox' comes from a package source that is not marked as trusted. Are you sure you want to install software from 'chocolatey'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- Firefox 35.0.1 Installed Chocolatey chocolatey Bringing together all kind... |
OneGet & Chocolatey – still WIP
Even though Firefox appeared as installed above, it did not actually install. This is because Chocolatey support was removed in the latest WMF 5.0 preview I had installed. To get it back I had to install the experimental version of OneGet
. Here’s me installing PeaZip:
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 |
PS> Install-Package -Name peazip -Verbose VERBOSE: Skipping package provider provider 'NuGet'-- missing required option 'Microsoft.OneGet.Utility.Collections.ReEnumerable`1[System.String]' VERBOSE: The -Repository parameter was not specified. PowerShellGet will use all of the registered repositories. VERBOSE: Getting the provider object for the OneGet Provider 'NuGet'. VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/' and OneGetProvider is 'NuGet'. VERBOSE: Performing the operation "Install Package" on target "Package 'peazip' v'5.5.0.20141130' from 'chocolatey'". The package 'peazip' comes from a package source that is not marked as trusted. Are you sure you want to install software from 'chocolatey'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): VERBOSE: NuGet: Installing 'peazip 5.5.0.20141130'. VERBOSE: NuGet: Successfully installed 'peazip 5.5.0.20141130'. VERBOSE: CreateFolder Success C:\Users\Rakhesh\AppData\Local\Temp\chocolatey\peazip VERBOSE: GetChocolateyWebFile peazip => http://www.peazip.org/downloads/peazip-5.5.0.WIN64.exe VERBOSE: Launching Process-EXE :'C:\Users\Rakhesh\AppData\Local\Temp\chocolatey\peazip\peazipinstall.EXE' VERBOSE: Process Exited Successfully. «{0}» «C:\Users\Rakhesh\AppData\Local\Temp\chocolatey\peazip\peazipinstall.EXE» VERBOSE: Package Successfully Installed peazip VERBOSE: Installation Successful «peazip» VERBOSE: True VERBOSE: False Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- peazip 5.5.0.201... Installed Chocolatey chocolatey A cross-platform file arch... |
For comparison here’s the same output with the non-experimental version of OneGet
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PS C:\Windows\system32> Install-Package -Name peazip -Verbose VERBOSE: Skipping package provider provider 'NuGet'-- missing required option 'Microsoft.OneGet.Utility.Collections.ReEnumerable`1[System.String]' VERBOSE: The -Repository parameter was not specified. PowerShellGet will use all of the registered repositories. VERBOSE: Getting the provider object for the OneGet Provider 'NuGet'. VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2/' and OneGetProvider is 'NuGet'. VERBOSE: Performing the operation "Install Package" on target "Package 'peazip' v'5.5.0.20141130' from 'chocolatey'". The package 'peazip' comes from a package source that is not marked as trusted. Are you sure you want to install software from 'chocolatey'? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): VERBOSE: NuGet: GET http://chocolatey.org/api/v2/Packages(Id='peazip',Version='5.5.0.20141130') VERBOSE: NuGet: GET http://chocolatey.org/api/v2/package/peazip/5.5.0.20141130 VERBOSE: NuGet: Installing 'peazip 5.5.0.20141130'. VERBOSE: NuGet: Successfully installed 'peazip 5.5.0.20141130'. Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- peazip 5.5.0.201... Installed Chocolatey chocolatey A cross-platform file arch... |
As you can see it doesn’t really download anything …
Here’s a list of providers OneGet
is aware of:
1 2 3 4 5 6 7 8 9 10 |
PS> Get-PackageProvider Name Version DynamicOptions ---- ------- -------------- msu 10.0.9800.0 {} ARP 10.0.9800.0 {IncludeWindowsInstaller} msi 10.0.9800.0 {AdditionalArguments} Chocolatey 2.8.4.30 {SkipDependencies, ContinueOnFailure, ExcludeVersion, ForceX86...} NuGet 2.8.4.30 {Destination, SkipDependencies, ContinueOnFailure, ExcludeVersion...} PSModule 10.0.9800.0 {OneGetProvider, Location, InstallUpdate, InstallationPolicy...} |
ARP stands for Add/ Remove Programs. With the experimental version one can list the programs in Add/ Remove programs:
1 2 3 4 5 6 7 8 9 10 11 |
PS> Get-Package -ProviderName ARP Name Version Status ProviderName Source Summary ---- ------- ------ ------------ ------ ------- CDisplayEx 1.10.18 Installed ARP Microsoft Azure Compute Em... 2.5.6496.10 Installed ARP Microsoft Visual Studio 20... 10.0.50903 Installed ARP Microsoft Office Professio... 15.0.4569... Installed ARP Microsoft Visio Profession... 15.0.4569... Installed ARP TeraCopy 2.3 Installed ARP PeaZip 5.5.0 (WIN64) Installed ARP |
The MSI and MSU providers are what you think they are (for installing MSI, MSP (patch) and MSU (update) packages). You can install & uninstall MSI packages via OneGet
. (But can you specify additional parameters while installing MSI? Not yet, I think …)
That’s it then!