setup automation with powershellpshdo.com/storage/slides/setupautomationwithpowershell.pdfsetup...

27
Setup Automation with PowerShell Forging the weapon of one man’s war against manual setup checklists Aaron Jensen “Software” Architect WebMD Health Services http://splatteredbits.com http://pshdo.com

Upload: others

Post on 07-Oct-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Setup Automation with PowerShell

Forging the weapon of one man’s war against manual setup checklists

Aaron Jensen“Software” Architect

WebMD Health Serviceshttp://splatteredbits.com

http://pshdo.com

Page 2: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Thanks*• WebMD Health Services and Chris Brooks

• Contributors: Scott Araujo and Charlie Shopsin

• Presentation Review Team: Scott Araujo, Dan Beutler, Shawn Goddard, Matt McLuckie, John Veneruso, Todd Whaley

• Open Source Bridge

* All names in reverse descending alphabetical order by last name

Page 3: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Carbon

Page 4: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup
Page 5: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup
Page 6: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup
Page 7: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

* Ability to fly is symbolic and not guaranteed. Nothing will make you as awesome as Superman, unless you’re Bruce Wayne.

Page 8: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Why Carbon?

Page 9: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Automation

Do it once manually, shame on me. Do it twice manually, I’ve got no business writing software or doing anything with computers really, so fire me so I can find a job mowing lawns or something.

Page 10: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Automation Increases Bandwidth

0

1

2

3

4

5

6

7

8

9

10

1 2 3 4 5 6 7 8 9 10

1

2

3

4

5

6

7

8

9

10

5 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9

Tota

l Hou

rs

Times Performed

Automated Manual

Page 11: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Automation Increases Quality

Page 12: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

In the beginning…

UNIX

Page 13: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

WindowsBusinessOn  Error  Resume  NextFor  Each  Disk  In  GetObject(  _        "winmgmts:").InstancesOf  ("CIM_LogicalDisk")                WScript.Echo  "Instance:",  Disk.Path_.RelpathNextIf  Err  <>  0  Thenset  lasterr  =  CreateObject("WbemScripting.SWbemLastError")        Wscript.echo  lasterr.OperationEnd  If

Page 14: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

WindowsServer/.NET<target  name=”build”>    <exec  program=”${MSBuildPath}”>        <arg  line=’”${SolutionFile}”‘  />        <arg  line=”/property:Configuration=${SolutionConfiguration}”  />        <arg  value=”/target:Rebuild”  />        <arg  value=”/verbosity:normal”  />        <arg  value=”/nologo”  />        <arg  line=’/logger:”C:\Program  Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll”‘/>    </exec></target>

<Target  Name="AfterBuild"  Condition="  '$(Configuration)'  ==  'Release'  ">        <CreateItem  Condition="'%(Extension)'=='.dll'"  Include="@(ReferenceCopyLocalPaths)">                <Output  TaskParameter="Include"  ItemName="IlmergeAssemblies"  />        </CreateItem>        <Exec  Command="&quot;$(ProjectDir)..\..\..\tools\IlMerge\Ilmerge.exe&quot;  /targetplatform:&quot;v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319&quot;  /ndebug  /out:@(MainAssembly)  &quot;@(IntermediateAssembly)&quot;  @(IlmergeAssemblies-­‐>'&quot;%(FullPath)&quot;',  '  ')"  />        <Delete  Files="@(ReferenceCopyLocalPaths-­‐>'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"  /></Target>

Page 15: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

NAnt/MSBuild

Page 16: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

PowerShell<#.SYNOPSISPackages  and  publishes  Carbon  packages.#>

#  Copyright  2012  Aaron  Jensen#  #  Licensed  under  the  Apache  License,  Version  2.0  (the  "License");#  you  may  not  use  this  file  except  in  compliance  with  the  License.#  You  may  obtain  a  copy  of  the  License  at#  #          http://www.apache.org/licenses/LICENSE-­‐2.0#  #  Unless  required  by  applicable  law  or  agreed  to  in  writing,  software#  distributed  under  the  License  is  distributed  on  an  "AS  IS"  BASIS,#  WITHOUT  WARRANTIES  OR  CONDITIONS  OF  ANY  KIND,  either  express  or  implied.#  See  the  License  for  the  specific  language  governing  permissions  and#  limitations  under  the  License.

[CmdletBinding()]param()

Set-­‐StrictMode  -­‐Version  Latest$ErrorActionPreference  =  'Stop'$PSScriptRoot  =  Split-­‐Path  -­‐Parent  $MyInvocation.MyCommand.Definition

$licenseFileName  =  'LICENSE.txt'

$releaseNotesFileName  =  'RELEASE  NOTES.txt'$releaseNotesPath  =  Join-­‐Path  $PSScriptRoot  $releaseNotesFileName  -­‐Resolve$releaseNotes  =  Get-­‐Content  $releaseNotesPath

if(  $releaseNotes[0]  -­‐notmatch  "^\#  (\d+\.\d+\.\d+)\s*"  ){        Write-­‐Error  "Missing  version  from  release  notes  file.    The  first  line  must  contain  the  version  about  to  be  released."        exit}$version  =  [Version]$matches[1]$releaseNotes[0]  =  "#  $version  ($((Get-­‐Date).ToString("d  MMMM  yyyy")))"$releaseNotes  |  Out-­‐File  -­‐FilePath  $releaseNotesPath  -­‐Encoding  OEM

Copy-­‐Item  (Join-­‐Path  $PSScriptRoot  LICENSE.txt  -­‐Resolve)  (Join-­‐Path  $PSScriptRoot  Carbon\  -­‐Resolve)

$carbonZipFileName  =  "Carbon-­‐$version.zip"$zipAppPath  =  Join-­‐Path  $PSScriptRoot  Tools\7-­‐Zip\7za.exe  -­‐Resolve

Push-­‐Location  $PSScriptRoottry{        if(  Test-­‐Path  $carbonZipFileName  -­‐PathType  Leaf  )        {                Remove-­‐Item  $carbonZipFileName        }

       &  $zipAppPath  a  $carbonZipFileName  .\Carbon        &  $zipAppPath  a  $carbonZipFileName  $licenseFileName        &  $zipAppPath  a  $carbonZipFileName  $releaseNotesFileName                hg  commit  -­‐m  "Adding  release  date  for  version  $version  to  $releaseNotesFileName."  $releaseNotesFileName        hg  tag  $version}finally{        Remove-­‐Item  (Join-­‐Path  $PSScriptRoot  Carbon\$licenseFileName)        Pop-­‐Location}

Page 17: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Layers of Abstraction

Windows/Win32 APIs

.NET

PowerShell

Carbon

appcmd.exemsiexec.exe

net.exenetsh.exe

sc.exeservermanagercmd.exe

ocsetup.exe…

Page 18: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

CarbonActive DirectoryCertificatesComputerCryptography.NETFile SystemHosts FileIISINI FilesMercurial

MSMQPerformance CountersPowerShellSecuritySharesUsers and GroupsWindows FeaturesWindows FirewallWindows Services

Page 19: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

ACTIVE DIRECTORY • Get-ADDomainController • Get-ADUser • Format-ADSpecialCharacters

CERTIFICATES • Get-Certificate • Get-CertificateStore • Get-SslCertificateBinding • Get-SslCertificateBindings • Install-Certificate • Remove-Certificate • Remove-SslCertificateBinding • Set-SslCertificateBinding • Test-SslCertificateBinding COMPUTER • Disable-IEEnhancedSecurityConfiguration • Enable-IEActiviationPermissions • Invoke-WindowsInstaller • Remove-EnvironmentVariable • Set-EnvironmentVariable • Test-OSIs32Bit • Test-OSIs64Bit CRYPTOGRAPHY • Protect-String • Unprotect-String .NET • Set-DotNetAppSetting • Set-DotNetConnectionString FILE SYSTEM • Get-FullPath • Get-PathCanonicalCase • Get-PathRelativeTo • New-Junction • New-TempDir

• Remove-Junction • Test-PathIsJunction HOSTS FILE • Get-PathToHostsFile • Reset-HostsFile • Set-HostsEntry IIS • Add-IisDefaultDocument • Get-IisHttpRedirect • Get-IisVersion • Get-IisWebsite • Install-IisApplication • Install-IisAppPool • Install-IisVirtualDirectory • Install-IisWebsite • Invoke-AppCmd • Remove-IisWebsite • Set-IisAnonymousAuthentication • Set-IisBasicAuthentication • Set-IisDirectoryBrowsing • Set-IisHttpRedirect • Set-IisSslFlags • Set-IisWebsiteSslCertificate • Set-IisWindowsAuthentication • Test-IisAppPoolExists • Unlock-IisBasicAuthentication

INI FILES • Set-IniEntry • Split-Ini

MERCURIAL • Set-HgDefaultPushUrl MSMQ • Get-MsmqMessageQueue • Get-MsmqMessageQueuePath • Grant-MsmqMessageQueuePermissions

• Install-Msmq • Install-MsmqMessageQueue • Remove-MsmqMessageQueue • Test-MsmqMessageQueue

PERFORMANCE COUNTERS • Get-PerformanceCounters • Install-PerformanceCounter • Test-PerformanceCounter • Test-PerformanceCounterCategory • Uninstall-PerformanceCounter POWERSHELL • Complete-Jobs • Get-PowerShellPath • Invoke-PowerShell • Test-PowerShellIs32Bit • Test-PowerShellIs64Bit

POWERSHELL REMOTING • Add-TrustedHosts • Get-TrustedHosts • Set-TrustedHosts SECURITY • Assert-AdminPrivileges • Convert-SecureStringToString • Grant-Permissions • New-Credential • Test-AdminPrivileges SERVICES • Grant-ServiceControlPermission • Install-Service • Invoke-SubInAcl • Remove-Service • Restart-RemoteService SHARES • Install-Share

USERS AND GROUPS • Add-GroupMembers • Get-WmiLocalUserAccount • Install-Group • Install-User • Remove-User • Test-User WINDOWS FEATURES • Install-WindowsFeatureIis • Install-WindowsFeatureMsmq • Install-WindowsFeatures • Test-WindowsFeature • Uninstall-WindowsFeature

WINDOWS FIREWALL • Assert-FirewallConfigurable • Disable-FirewallStatefulFtp • Enable-FirewallStatefulFtp • Get-FirewallRules • Test-FirewallStatefulFtp

TYPES • Diagnostics.Process.ParentProcessID • ServiceProcess.ServiceController.StartMode • ServiceProcess.ServiceController.UserName • IO.DirectoryInfo.IsJunction • IO.DirectoryInfo.TargetPath

Carbon

Page 20: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Why Carbon?

Page 21: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

faux Environment

Build Server

WebServer

Deploys

•Runs CruiseControl.NET Windows Service•Service runs as a specific domain account

•Runs SSL-enabled .NET web application•Uses database server•Code is deployed from build server via a Windows share

DatabaseServer

Page 22: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Code

Page 23: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

<meta />

• Automated tests

• Continuous Integration

• Documentation

• Semantic Versioning – semver.org

Page 24: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Semantic Versioning

Major.Minor.Patch, e.g. 1.8.3

Page 25: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Get Involved @ Hacker Lounge

Page 27: Setup Automation with PowerShellpshdo.com/storage/slides/SetupAutomationWithPowerShell.pdfSetup Automation with PowerShell Forging the weapon of one man’s war against manual setup

Q&A