Example Shell
Creating a portable virtual server lab
Presentation for the Singapore PowerShell User Group
8. April 2017
Peter Hahndorf
Solution Architect
Hahndorf Consulting
https://hahndorf.eu

Agenda

  • Intro
  • The host
  • Creating new VMs
  • Using custom scripts
  • DSC Resources
  • Using DSC push and pull configurations
  • Alternatives

Motivation

backpack
  • I quit my day job in London in 2005 and started travelling
  • No Laptop to work with (too heavy)
  • USB drive to store photos on
  • Often no network connectivity
  • Still needed to get some work done
  • Secure way to connect to servers and online banking

Around the world

map

The host

Hardware

I am using Windows Server 2016 as a host OS, it boots like a Windows To Go system from an external USB (2 or 3) drive. We can use any normal SATA SSD drive and an USB-3 adapter, we could also connect the drive internally via SATA.
The host PC needs to have a 64bit CPU with Hyper-V support, the more memory the better.

New Installation

Using a PowerShell script, I can set up a new Windows To Go installation with basic setup is about an hour.
As this is for testing and evaluation purposes, we can use the 180 day trial version of Windows server.

Posh Profiles

Using a command line interface to start my Windows programs since the early 1990s, now using PowerShell profiles.
ex, um, dm, vm, ev, ser, word, n, code, ise, vs, sql, su

Creating new VMs

Hyper-V and Hyper-Cmdlets

Using custom scripts to quickly set create new VMs from scratch. A single one:
New-LabVM -id 1 -os 2016GUI
or several
New-vLab -count 5 -os 2016Core
I can also control them all with single commands
Start-vLab.ps1
Save-vLab.ps1
CheckPoint-vLab.ps1
Remove-LabVM.ps1 -ids 1,2,5

Using custom scripts

Automate common tasks

Before DSC was around I created many custom scripts to set up servers.
Setup-OS.ps1
Setup-iis.ps1 -role -hacon
Setup-DemoWebServer.ps1 -iis -sites 5
Setup-AD.ps1 -prepare -forest -SiteName Singapore

Mysore Project

I created scripts to completely automate the setup of my productions servers:
Web-Server, web-sites, SQL-Server, database restore, custom apps and services. certificates, security settings.

Desired State Configuration

What is PowerShell DSC?

You define the desired configuration of your servers in configuration files using a PowerShell like syntax.
Configuration MyServer {

    Node Localhost {

        File BinFolder
        {
            Ensure = "Present"
            Type = "Directory"
            DestinationPath = "C:\bin"
        }
    }
}

DSC Resources

DSC is using resources to be configured to define the state of the server.
Get-DscResource | Select Name

Included in Windows (23)

Out of the box in Windows, the newer the OS, the more resources you will have.

DSC Resource Kit

Many more resources, now open source but strongly controlled by the Microsoft PowerShell team

Community Resources

Even more resource written by the community, before writing your own, Bing around a bit.

Using DSC locally

Using the push mode

We create a DSC configuration and execute it manually on a local or different server.

Using a DSC Pull Server

Server Setup

  • Using a web server (SMB share is possible)
  • Installing the pull server components
  • Providing configurations to be distributed

Client Setup

  • Tell the LC about the pull server
  • Sit back and relaxed

Alternatives to DSC

chef.io

puppet.com

powershellgallery.com/packages/Carbon/

Using your own scripts

How to choose?

Authoring DSC Resources

Need your own resources?

There are still some things you can not do with the existing DSC resources, so you can/have to write your own.

But a topic for a different day.

Things DSC can't do!

  • Make sure things are NOT there.

Questions?

About Me

Peter Hahndorf
Solution Architect / World Traveller
Hahndorf Consulting

My blog, open source projects and other tech stuff:
https://peter.hahndorf.eu/tech/

For more about my travels:
https://peter.hahndorf.eu/trip/

Contact me at:
https://www.twee.net/contact/

peter