Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
KEEP CALM
and
LEARN
POWERSHELL
YouTube: https://www.youtube.com/watch?v=V5Gjx4jM91A
Robert Tinga
Business Development Manager QUINTOR
rtinga@quintor.nl
06 - 21862066
Introduction
Quintor
JAVA
.NET
MOBILE
GRONINGEN
AMERSFOORT
DEN HAAG
112 EMPLOYEES
ATLASSIAN
MS TFS
AGILE/SCRUM
ANALYSE
Employees
0
20
40
60
80
100
120
Groningen Amersfoort Den Haag
KEEP CALM
and
LEARN
POWERSHELL
Jeroen Swart
.NET Architect
jswart@quintor.nl
• Developer >= 1996
• Mainframe/assembler, Microsoft/C++, .NET/C#
• .NET >= ...
REPL
DSCRemote
PowerShell
Verb
Commands
Build &
Release Management
Functions
PowerShell
Package
Management
Modules
NuGet
S...
> _
− REPL (Read Evaluate Print Loop)
− .NET
− Commands
− Parameters
− Objecten
− Command pipeline
Show-Code
> Commands
− [Verb]-[Prefix][Noun]
− Verb: Get, New, Update, … (Get-Verb)
− Prefix: VM, AD, Azure, Sql, …
− Noun: Switch, ...
> Command pipeline
− Get-Process | Sort ProcessName | Select *
− Select-Object select
− Sort-Object sort
− Where-Object wh...
> Select-Object
− Specify which properties to return
− Select ProcessName,Description
− Select *
− Specify how many object...
> Sort-Object
− Specify order of objects
− Sort ProcessName
− Specify direction
− Sort ProcessName -Descending
− Get-Proce...
> Where-Object
− Filter objects by property
− Where -Property ProcessName -EQ 'powershell'
− Filter objects using script
−...
> ForEach-Object
− Repeat for each object
− ForEach { Write-Host $_.ProcessName }
− Get-Process |% { Write-Host "$($_.Proc...
> Command pipeline
− Measure-Object
− Group-Object
− Compare-Object
− Tee-Object
> Format-*
− Format-Table (ft)
− -AutoSize (ft –a)
− Format-List (fl)
− Format-Wide (fw)
− -Column (fw –c 3)
− Get-Command...
> Out-*
− Out-Default
− Out-File
− Out-Null
− Out-String
− Out-GridView (ogv)
− Get-Command out-*
> ConvertTo-* / ConvertFrom-*
− ConvertTo-Json, ConvertFrom-Json
− ConvertTo-Xml (, Get-Content)
− ConvertTo-Csv, ConvertF...
> Advanced pipeline
− -PassThru
− Multiline with `
− Multi-command on single line with ;
− Select @{ Name = $_.Name; Type ...
Show-Code
> Hosts
− Console
− ISE (Integrated Script Environment)
− Visual Studio Extension (2015, 2013, 2012)
− Visual Studio Code ...
> Host environment
− Get-Variable
− $Host
− $Profile
− $PSVersionTable
> $Host
− Console
− ISE
> $Profile
− Current user / All users
− Current host / All hosts
− $profile
− Current user, current host
− $profile.AllUse...
> $Profile
$global:CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
function prompt
{
$Host.UI.RawU...
> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.122
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion ...
> Strings
− Literals
− 'Name: $Name'
− "Name: $Name"
− Format
− 'Name: {0}' –f $Name
− Expression
− "Name: $user.Name"
− "...
> Strings & regular expressions
− Match
− 'PowerShell' –match 'sh'
− 'PowerShell' –match '^P'
− 'PowerShell' –match 'P$‘
−...
> Arrays & objects
− Command output is array or object
− When Parameter type is Array, provide
either array or single obje...
> Arrays
− $a = 1,2
− $a = @(1)
− $a = @()
− $a = 1..5
− $a += 6
− $a.GetType() -> System.Array
− $a.Length
− $a.Contains(...
> Objects (HashTable)
− $o = @{}
− $o = @{ Name = 'me' }
− $o = @{
Name = 'me'
PowerShell = $true
}
− $o = @{ Name = 'me';...
> Objects (PSCustomObject)
$o = New-Object PSCustomObject `
| Add-Member -MemberType NoteProperty -Name 'Name' -Value 'me'...
> Objects
− $o.Name
− $o.'Name'
− $o = @{
Name = 'me'
PowerShell = $true
}
− $o = @{ Name = 'me'; PowerShell = $true }
> Scripts
− Collection of commands
− Conditional statements (if/else, etc.)
− Parameters
− Output
− Execute using . Or &
−...
> Scripts – if/else
if ($condition) {
}
elseif ($otherCondition) {
}
else {
}
if (Test-Path -Path $path) {
}
if (Get-Servi...
> Scripts – if/else
− -eq, -ne
− -lt, -gt, -le, -ge
− -like, -match, -notlike, -notmatch
− -contains, -in, -notcontains, -...
> Scripts – switch/case
switch ($value) {
1 { }
2 { }
default { }
}
switch ($value) {
'1' { }
'2' { }
default { }
}
switch...
> Scripts – foreach
foreach ($item in $items) {
# use $item
}
$items |% {
# use $_
}
Basic syntax
Alternative
> Scripts – for
for ($index = 0; $index -lt 10; $index++) {
# use $items[$index]
}
Basic syntax
> Scripts – try/catch
try {
throw 'Serious error'
throw [InvalidOperationException]'Serious error'
}
catch [InvalidOperati...
> Scripts – parameters
− Name
− Default
− Type
− Mandatory
− ValueFromPipeline
− ParameterSetName
− Validation
− ValidateS...
> Scripts – output
− return
− Write-Output
− Write-Host
− Write-Verbose
− CmdletBinding
− -Verbose
return 'The result'
The...
> Scripts – output
− Write-Verbose -Verbose $VerbosePreference
− Write-Debug -Debug $DebugPreference
− Write-Warning -Warn...
> Scripts – lifecycle
param (
)
# script-body here
. .Script.ps1 -Value '1','2'
'1','2' | . .Script.ps1
− $Value = '1','2'...
> Scripts – lifecycle
param (
)
begin {
}
process {
# script-body here
}
end {
}
. .Script.ps1 -Value '1','2'
'1','2' | . ...
Show-Code
> Functions
function Verb-PrefixNoun {
}
function Verb-PrefixNoun {
param (
[string]$Value
)
# function-body here
$Value
}...
> Modules
− PowerShell Script or C#
− C#
− System.Management.Automation namespace
− Cmdlet base-class
− Cmdlet attribute
−...
> Modules
− Import-Module
− .psm1
− .psm1 + .psd1
− New-ModuleManifest
− Update-ModuleManifest
− Test-ModuleManifest
− Scr...
> Modules
− Import-Module –Path '...'
− Import-Module –Name '...'
− System
− %windir%System32WindowsPowerShellv1.0Modules
...
> Modules
− Get-Module
− Get-Module –ListAvailable
− Remove-Module
− Import-Module –Force
• NuGet
• Chocolatey
• PowerShell Package Management
• TFS Build
• TFS Release Management
• Remote PowerShell
• PowerShell...
• NuGet
• Chocolatey
• PowerShell Package Management
> Select PowerShell | More
> NuGet
− zip, maar .nupkg
− lib
− net45
− net40
− portable-win+net45+wp8+win8+wpa81
− content
− tools
− init.ps1
− .psm1
...
> NuGet
− init.ps1
− installPath
− toolPath
− package
− project
− EnvDTE.Project
− ProjectItems
− DTE EnvDTE.DTE
> NuGet
− Add/modify files & content in a project
− Build and/or run the solution
− Code generation
− Entity Framework Mig...
Show-Code
> Chocolatey
− Windows Package Manager
− choco list
− choco install
− NuGet-based
− nuspec
− tools
− chocolateyInstall.ps1...
> Chocolatey
− Install-ChocolateyPackage
− Install-ChocolateyZipPackage
− Install-ChocolateyVsixPackage
− Install-Chocolat...
> Chocolatey
Install-ChocolateyPackage `
'notepadplusplus' `
'exe' `
'/S' `
'https://notepad-plus-plus.org/repository/6.x/...
> PowerShell Modules
− xcopy
− System, All users, Current user
− Chocolatey package
− xcopy
− PowerShell Package Managemen...
> PowerShell Package Management
− Package Manager Manager
> PowerShell Package Management
− Module
− Script
− Package
− Find, Install, Update, Publish, Save
− Find-Module
− Install...
Show-Code
• TFS Build
• TFS Release Management
> Select PowerShell | More
> TFS Build
− XAML Build
− Task-based build
− Script (in VC)
− Arguments
> TFS Release Management
− XAML
− Task-based
− TFS 2015 Update 2
> TFS Release Management
− Remote PowerShell
− PowerShell Scripts
− PowerShell Modules
− PowerShell DSC
− PowerShell Packa...
> TFS Release Management
Build
Drop-
location
RM
Target-
servers
Trigger release Execute script
Copy files to servers
> TFS Release Management
Build
Package
Source
RM
Target-
servers
Chocolatey Packages
PowerShell Modules
Trigger release
Re...
• Remote PowerShell
• PowerShell DSC
• Server Management
> Select PowerShell | More
> Remote PowerShell
− Enter-PSSession & Exit-PSSession
− New-PSSession & Remove-PSSession
− Invoke-Command -Session
> Remote PowerShell
− Enable remoting
− Enable-PSRemoting
− Check configuration
− Test-WSMan
− Limit access
− Set-Item `
w...
> Remote PowerShell
− 'Double Hop'
− CredSSP & Credential
− Server
− Enable-WSManCredSSP -Role Server
− Client
− Enable-WS...
> PowerShell DSC
$server = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
if($Credential) {
$server.Conne...
> PowerShell DSC
bSqlDatabase Database {
Ensure = "Present"
Name = $DatabaseName
}
PowerShell DSC
> PowerShell DSC
− Desired State Configuration
− Declarative
− Configuration
− Resource
− Get
− Test
− Set
> PowerShell DSC
− Push vs Pull
Show-Code
> Server Management
− Server
− Processes
− Services
− Resources (RAM, CPU, …)
− IIS
− Websites
− App pools
− Logging
• notes in ppt
• MSDN
• Windows PowerShell
• PowerShell DSC
• PowerShell SDK
• Blogs
• Windows PowerShell Blog
• Hey Scrip...
• PowerShell Workflow
• Debugging (incl. remote)
• Classes
• ISE
• Automation
• Extensions/Add-ons
• Unit testing (Pester)...
?
VRAGEN
Power shell voor developers
Prochain SlideShare
Chargement dans…5
×

Power shell voor developers

628 vues

Publié le

De slides van de Quintor presentatie in maart 2016 over PowerShell

Publié dans : Logiciels

Power shell voor developers

  1. 1. KEEP CALM and LEARN POWERSHELL
  2. 2. YouTube: https://www.youtube.com/watch?v=V5Gjx4jM91A
  3. 3. Robert Tinga Business Development Manager QUINTOR rtinga@quintor.nl 06 - 21862066 Introduction
  4. 4. Quintor JAVA .NET MOBILE GRONINGEN AMERSFOORT DEN HAAG 112 EMPLOYEES ATLASSIAN MS TFS AGILE/SCRUM ANALYSE
  5. 5. Employees 0 20 40 60 80 100 120 Groningen Amersfoort Den Haag
  6. 6. KEEP CALM and LEARN POWERSHELL
  7. 7. Jeroen Swart .NET Architect jswart@quintor.nl • Developer >= 1996 • Mainframe/assembler, Microsoft/C++, .NET/C# • .NET >= 2001 • Quintor >= 2011 • .NET competentie • ALM & .NET ontwikkelstraat
  8. 8. REPL DSCRemote PowerShell Verb Commands Build & Release Management Functions PowerShell Package Management Modules NuGet StringsPipeline TasksTFS Scripts Chocolatey PowerShell Gallery Objects Arrays
  9. 9. > _ − REPL (Read Evaluate Print Loop) − .NET − Commands − Parameters − Objecten − Command pipeline
  10. 10. Show-Code
  11. 11. > Commands − [Verb]-[Prefix][Noun] − Verb: Get, New, Update, … (Get-Verb) − Prefix: VM, AD, Azure, Sql, … − Noun: Switch, User, Website, Database − Get-Service − Get-VMSwitch − New-ADUser − Start-AzureWebsite − Backup-SqlDatabase
  12. 12. > Command pipeline − Get-Process | Sort ProcessName | Select * − Select-Object select − Sort-Object sort − Where-Object where, ? − ForEach-Object foreach, %
  13. 13. > Select-Object − Specify which properties to return − Select ProcessName,Description − Select * − Specify how many objects to return − Select –First 5 − Select –First 5 –Skip 5 − Select –Last 10 − Get-Process | Select ProcessName,Description –First 10
  14. 14. > Sort-Object − Specify order of objects − Sort ProcessName − Specify direction − Sort ProcessName -Descending − Get-Process | Sort ProcessName,Description
  15. 15. > Where-Object − Filter objects by property − Where -Property ProcessName -EQ 'powershell' − Filter objects using script − Where { $_.ProcessName -eq 'powershell' } − Get-Process |? { $_.ProcessName -like 'po*' }
  16. 16. > ForEach-Object − Repeat for each object − ForEach { Write-Host $_.ProcessName } − Get-Process |% { Write-Host "$($_.ProcessName)" }
  17. 17. > Command pipeline − Measure-Object − Group-Object − Compare-Object − Tee-Object
  18. 18. > Format-* − Format-Table (ft) − -AutoSize (ft –a) − Format-List (fl) − Format-Wide (fw) − -Column (fw –c 3) − Get-Command format-*
  19. 19. > Out-* − Out-Default − Out-File − Out-Null − Out-String − Out-GridView (ogv) − Get-Command out-*
  20. 20. > ConvertTo-* / ConvertFrom-* − ConvertTo-Json, ConvertFrom-Json − ConvertTo-Xml (, Get-Content) − ConvertTo-Csv, ConvertFrom-Csv − ConvertTo-Html − Get-Command convertto-*,convertfrom-*
  21. 21. > Advanced pipeline − -PassThru − Multiline with ` − Multi-command on single line with ; − Select @{ Name = $_.Name; Type = 'Foo' } − Force expression evaluation using brackets ()
  22. 22. Show-Code
  23. 23. > Hosts − Console − ISE (Integrated Script Environment) − Visual Studio Extension (2015, 2013, 2012) − Visual Studio Code Extension − PowerGUI − PowerShell Plus − Custom − [insert your application name here]
  24. 24. > Host environment − Get-Variable − $Host − $Profile − $PSVersionTable
  25. 25. > $Host − Console − ISE
  26. 26. > $Profile − Current user / All users − Current host / All hosts − $profile − Current user, current host − $profile.AllUsersAllHosts − $profile.AllUsersCurrentHosts − $profile.CurrentUsersAllHosts − $profile.CurrentUsersCurrentHost $profile.AllUsersAllHosts C:WindowsSystem32WindowsPowerShellv1.0profile.ps1 $profile.AllUsersCurrentHosts C:WindowsSystem32WindowsPowerShellv1.0Microsoft.PowerShell_profile.ps1 $profile.CurrentUsersAllHosts C:UsersjswartDocumentsWindowsPowerShellprofile.ps1 $profile.CurrentUsersCurrentHost C:UsersjswartDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1 $profile (console) C:UsersjswartDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1 $profile (ISE) C:UsersjswartDocumentsWindowsPowerShellMicrosoft.PowerShellISE_profile.ps1
  27. 27. > $Profile $global:CurrentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent() function prompt { $Host.UI.RawUI.WindowTitle = "$($CurrentUser.Name) - $(Get-Location)" Write-Host 'PS >' -NoNewline return ' ' }
  28. 28. > $PSVersionTable Name Value ---- ----- PSVersion 5.0.10586.122 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.10586.122 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1
  29. 29. > Strings − Literals − 'Name: $Name' − "Name: $Name" − Format − 'Name: {0}' –f $Name − Expression − "Name: $user.Name" − "Name: $($user.Name)" Name: $Name Name: Jeroen Name: Jeroen Name: Hashtable.Name Name: Jeroen
  30. 30. > Strings & regular expressions − Match − 'PowerShell' –match 'sh' − 'PowerShell' –match '^P' − 'PowerShell' –match 'P$‘ − 'PowerShell' –cmatch 'p$' − Replace − 'PowerShell' -replace 'e','E' True True False False PowErShEll
  31. 31. > Arrays & objects − Command output is array or object − When Parameter type is Array, provide either array or single object as value
  32. 32. > Arrays − $a = 1,2 − $a = @(1) − $a = @() − $a = 1..5 − $a += 6 − $a.GetType() -> System.Array − $a.Length − $a.Contains(1) − $a[0]
  33. 33. > Objects (HashTable) − $o = @{} − $o = @{ Name = 'me' } − $o = @{ Name = 'me' PowerShell = $true } − $o = @{ Name = 'me'; PowerShell = $true }
  34. 34. > Objects (PSCustomObject) $o = New-Object PSCustomObject ` | Add-Member -MemberType NoteProperty -Name 'Name' -Value 'me' -PassThru ` | Add-Member -MemberType NoteProperty -Name 'PowerShell' -Value $true -PassThru
  35. 35. > Objects − $o.Name − $o.'Name' − $o = @{ Name = 'me' PowerShell = $true } − $o = @{ Name = 'me'; PowerShell = $true }
  36. 36. > Scripts − Collection of commands − Conditional statements (if/else, etc.) − Parameters − Output − Execute using . Or & − Execute using full or relative path (.) . .DoSomethingSmart.ps1 . '.DoSomethingSmart.ps1'
  37. 37. > Scripts – if/else if ($condition) { } elseif ($otherCondition) { } else { } if (Test-Path -Path $path) { } if (Get-Service 'MSSQL*') { } Basic syntax Using commands returning a boolean Using other commands if ($name -eq 'PowerShell' ) { } Using logical operators if ($condition -eq $true) { } Using explicit conditions
  38. 38. > Scripts – if/else − -eq, -ne − -lt, -gt, -le, -ge − -like, -match, -notlike, -notmatch − -contains, -in, -notcontains, -notin − And their case-sensitive version (-ceq, -clike, etc.) − And their (explicit) case-insensitive version (-ieq, -ilike, etc.) − -not, -or, -and, -xor − And their binary version (-bnot, -bor, etc.) − -is, -isnot
  39. 39. > Scripts – switch/case switch ($value) { 1 { } 2 { } default { } } switch ($value) { '1' { } '2' { } default { } } switch ($value) { { $_ -eq 1 } { } { $_ -in 2,3 } { } { $_ -like '4*' } { } { $_ -match '^5' } { } default { } } Basic syntax Using strings Using expressions
  40. 40. > Scripts – foreach foreach ($item in $items) { # use $item } $items |% { # use $_ } Basic syntax Alternative
  41. 41. > Scripts – for for ($index = 0; $index -lt 10; $index++) { # use $items[$index] } Basic syntax
  42. 42. > Scripts – try/catch try { throw 'Serious error' throw [InvalidOperationException]'Serious error' } catch [InvalidOperationException] { write-host 'InvalidOperationException' } catch { } finally { }
  43. 43. > Scripts – parameters − Name − Default − Type − Mandatory − ValueFromPipeline − ParameterSetName − Validation − ValidateSet − ValidateScript − switch param ( ) param ( $Value ) param ( $Value = 'The default value' ) param ( [string]$Value ) param ( [Parameter(Mandatory = $true)] [string]$Value ) param ( [Parameter(ValueFromPipeline = $true)] [string[]]$Value ) param ( [Parameter(ParameterSetName = ‘ByValue')] [string]$Value, [Parameter(ParameterSetName = 'ByCount')] [int]$Count ) . .Script.ps1 -Value 'foo' . .Script.ps1 –Count 42 param ( [ValidateSet('High', 'Low')] [string]$Value ) param ( [ValidateScript({ Test-Path -Path $_ -PathType Leaf })] [string]$Path ) param ( [switch]$Force ) if ($Force) { } if ($Force.IsPresent) { } . .Script.ps1 –Force True . .Script.ps1 False . .Script.ps1 –Force:$false False param ( [bool]$Force ) if ($Force) { } . .Script.ps1 –Force $true True . .Script.ps1 –Force $false False
  44. 44. > Scripts – output − return − Write-Output − Write-Host − Write-Verbose − CmdletBinding − -Verbose return 'The result' The result Write-Output 'The result' The result Write-Output 'The result' Write-Output ‘More result' The result More result Write-Host 'Message‘ Write-Host 'Message' -ForegroundColor Yellow Write-Host 'Message' -BackgroundColor Magenta ` -ForegroundColor White Write-Host ('Message {0}' -f 42) [CmdletBinding()] param ( ) Write-Verbose 'Verbose message‘
  45. 45. > Scripts – output − Write-Verbose -Verbose $VerbosePreference − Write-Debug -Debug $DebugPreference − Write-Warning -WarningAction $WarningPreference − Write-Error -ErrorAction $ErrorActionPreference − Write-Information -InformationAction $InformationPreference − Action/Preference − SilentlyContinue − Continue − Stop
  46. 46. > Scripts – lifecycle param ( ) # script-body here . .Script.ps1 -Value '1','2' '1','2' | . .Script.ps1 − $Value = '1','2' − $Value = '2' param ( [string[]]$Value ) # script-body here param ( [Parameter(ValueFromPipeline = $true)] [string[]]$Value ) # script-body here $Value
  47. 47. > Scripts – lifecycle param ( ) begin { } process { # script-body here } end { } . .Script.ps1 -Value '1','2' '1','2' | . .Script.ps1 − Begin − Process ($Value = '1','2') − End − Begin − Process ($Value = '1') − Process ($Value = '2') − End param ( ) begin { } process { # script-body here } end { } param ( [string[]]$Value ) begin { } process { # script-body here } end { } param ( [Parameter(ValueFromPipeline = $true)] [string[]]$Value ) begin { } process { # script-body here $Value } end { }
  48. 48. Show-Code
  49. 49. > Functions function Verb-PrefixNoun { } function Verb-PrefixNoun { param ( [string]$Value ) # function-body here $Value } function Verb-PrefixNoun { param ( [string[]]$Value ) begin { } process { # script-body here $Value } end { } }
  50. 50. > Modules − PowerShell Script or C# − C# − System.Management.Automation namespace − Cmdlet base-class − Cmdlet attribute − PowerShell Script − Collection of functions − .psm1 − .psd1
  51. 51. > Modules − Import-Module − .psm1 − .psm1 + .psd1 − New-ModuleManifest − Update-ModuleManifest − Test-ModuleManifest − Script-files function Get-SomeStuff { } function Update-SomeStuff { } function Remove-SomeStuff { } @{ Author = 'Jeroen Swart' RootModule = 'MyModule.psm1' ModuleVersion = '1.0.0.0' GUID = 'bbd0a9d3-8308-4e5b-9762-1cbc057dd1c4' Description = '...' PowerShellVersion = '4.0' FunctionsToExport = ( 'Get-SomeStuff', 'Update-SomeStuff', 'Remove-SomeStuff') } Get-ChildItem ` -Path "$PSScriptRootInternal" ` -Filter '*.ps1' |% { . $_.FullName } Get-ChildItem ` -Path "$PSScriptRootFunctions" ` -Filter '*.ps1' |% { . $_.FullName }
  52. 52. > Modules − Import-Module –Path '...' − Import-Module –Name '...' − System − %windir%System32WindowsPowerShellv1.0Modules − $pshomeModules − All users − %ProgramFiles%WindowsPowerShellModules − "$($env:ProgramFiles)WindowsPowerShellModules" − Current user − %UserProfile%DocumentsWindowsPowerShellModules − $homeDocumentsWindowsPowerShellModules
  53. 53. > Modules − Get-Module − Get-Module –ListAvailable − Remove-Module − Import-Module –Force
  54. 54. • NuGet • Chocolatey • PowerShell Package Management • TFS Build • TFS Release Management • Remote PowerShell • PowerShell DSC • Server Management > Select PowerShell | More
  55. 55. • NuGet • Chocolatey • PowerShell Package Management > Select PowerShell | More
  56. 56. > NuGet − zip, maar .nupkg − lib − net45 − net40 − portable-win+net45+wp8+win8+wpa81 − content − tools − init.ps1 − .psm1 − nuspec
  57. 57. > NuGet − init.ps1 − installPath − toolPath − package − project − EnvDTE.Project − ProjectItems − DTE EnvDTE.DTE
  58. 58. > NuGet − Add/modify files & content in a project − Build and/or run the solution − Code generation − Entity Framework Migrations − Manage windows & documents − Enhance Visual Studio UI
  59. 59. Show-Code
  60. 60. > Chocolatey − Windows Package Manager − choco list − choco install − NuGet-based − nuspec − tools − chocolateyInstall.ps1 − chocolateyUninstall.ps1
  61. 61. > Chocolatey − Install-ChocolateyPackage − Install-ChocolateyZipPackage − Install-ChocolateyVsixPackage − Install-ChocolateyEnvironmentVariable − Install-ChocolateyFileAssociation
  62. 62. > Chocolatey Install-ChocolateyPackage ` 'notepadplusplus' ` 'exe' ` '/S' ` 'https://notepad-plus-plus.org/repository/6.x/6.8.8/npp.6.8.8.Installer.exe' Notepadplusplus (chocolateyInstall.ps1) $packageName = 'GoogleChrome' $app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq 'Google Chrome'} if ($app) { $msiArgs = $('/x' + $app.IdentifyingNumber + ' /q REBOOT=ReallySuppress') Start-ChocolateyProcessAsAdmin $msiArgs 'msiexec' } GoogleChrome (chocolateyUninstall.ps1)
  63. 63. > PowerShell Modules − xcopy − System, All users, Current user − Chocolatey package − xcopy − PowerShell Package Management − PowerShell v5
  64. 64. > PowerShell Package Management − Package Manager Manager
  65. 65. > PowerShell Package Management − Module − Script − Package − Find, Install, Update, Publish, Save − Find-Module − Install-Package
  66. 66. Show-Code
  67. 67. • TFS Build • TFS Release Management > Select PowerShell | More
  68. 68. > TFS Build − XAML Build − Task-based build − Script (in VC) − Arguments
  69. 69. > TFS Release Management − XAML − Task-based − TFS 2015 Update 2
  70. 70. > TFS Release Management − Remote PowerShell − PowerShell Scripts − PowerShell Modules − PowerShell DSC − PowerShell Package Management (Chocolatey)
  71. 71. > TFS Release Management Build Drop- location RM Target- servers Trigger release Execute script Copy files to servers
  72. 72. > TFS Release Management Build Package Source RM Target- servers Chocolatey Packages PowerShell Modules Trigger release Retrieve packages Install packages
  73. 73. • Remote PowerShell • PowerShell DSC • Server Management > Select PowerShell | More
  74. 74. > Remote PowerShell − Enter-PSSession & Exit-PSSession − New-PSSession & Remove-PSSession − Invoke-Command -Session
  75. 75. > Remote PowerShell − Enable remoting − Enable-PSRemoting − Check configuration − Test-WSMan − Limit access − Set-Item ` wsman:localhostclienttrustedhosts [name] ` -Concatenate -Force
  76. 76. > Remote PowerShell − 'Double Hop' − CredSSP & Credential − Server − Enable-WSManCredSSP -Role Server − Client − Enable-WSManCredSSP -Role Client ` –DelegateComputer [machinename]
  77. 77. > PowerShell DSC $server = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)") if($Credential) { $server.ConnectionContext.Login = $Credential.UserName $server.ConnectionContext.SecurePassword = $credential.Password } $database = $server.Databases |? { $_.Name -eq $Name } if (-not $database) { $database = New-Object Microsoft.SqlServer.Management.Smo.Database($server, $Name) $database.Create() } PowerShell Script
  78. 78. > PowerShell DSC bSqlDatabase Database { Ensure = "Present" Name = $DatabaseName } PowerShell DSC
  79. 79. > PowerShell DSC − Desired State Configuration − Declarative − Configuration − Resource − Get − Test − Set
  80. 80. > PowerShell DSC − Push vs Pull
  81. 81. Show-Code
  82. 82. > Server Management − Server − Processes − Services − Resources (RAM, CPU, …) − IIS − Websites − App pools − Logging
  83. 83. • notes in ppt • MSDN • Windows PowerShell • PowerShell DSC • PowerShell SDK • Blogs • Windows PowerShell Blog • Hey Scripting Guy • ... • Books • Windows PowerShell in Action • Windows PowerShell Cookbook • Windows PowerShell for Developers • ... > Get-Help
  84. 84. • PowerShell Workflow • Debugging (incl. remote) • Classes • ISE • Automation • Extensions/Add-ons • Unit testing (Pester) • Azure (incl. PowerShell DSC) • OSS Packages & Modules > _
  85. 85. ? VRAGEN

×