|
| 1 | +# Nano Server |
| 2 | +# PSconf EU 2017 |
| 3 | +# Script Help for PreConf Nano Server and Container |
| 4 | + |
| 5 | +# Quick |
| 6 | + |
| 7 | +# Step 1 - Mount ISO Drive and Copy Content |
| 8 | + |
| 9 | +$destinationDir = "C:\NanoServer" |
| 10 | + |
| 11 | +$mounted = Mount-DiskImage -ImagePath "C:\Downloads\en_windows_server_2016_x64_dvd_9718492.iso" |
| 12 | +$driveLetter = ($mounted | Get-Volume).DriveLetter |
| 13 | +$sourcePath = $driveLetter + ":\NanoServer" |
| 14 | + |
| 15 | +robocopy "$sourcePath" "$destinationDir" "/MIR" #Copy Files with robocopy, more efficient than Copy-Item |
| 16 | + |
| 17 | +# More Advanced Example Mount |
| 18 | + |
| 19 | +$ImagePath= "C:\Downloads\en_windows_server_2016_x64_dvd_9718492.iso" |
| 20 | +$ISODrive = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter |
| 21 | +IF (!$ISODrive) { |
| 22 | +Mount-DiskImage -ImagePath $ImagePath -StorageType ISO |
| 23 | +} |
| 24 | +$ISODrive = (Get-DiskImage -ImagePath $ImagePath | Get-Volume).DriveLetter |
| 25 | +$ISODrive = $ISODrive + ":\" |
| 26 | + |
| 27 | +# Step 2 - Mount Module |
| 28 | + |
| 29 | +Import-Module ($destinationDir + "\NanoServerImageGenerator\NanoServerImageGenerator.psm1") |
| 30 | + |
| 31 | +# Step 3 - Create BasePath - Working Dir |
| 32 | + |
| 33 | +$BasePath = "C:\Nano" |
| 34 | + |
| 35 | +if(!$BasePath){ |
| 36 | + New-Item -Path $BasePath -ItemType Directory |
| 37 | +} else{ |
| 38 | + Write-Host "Der Pfad ""$BasePath"" existiert bereits" |
| 39 | +} |
| 40 | + |
| 41 | +# Step 4 - Let's see the new cmdlets |
| 42 | + |
| 43 | +Get-Command –module NanoServerImageGenerator |
| 44 | + |
| 45 | +# Step 5 Create a new Nano-Server-Image |
| 46 | + |
| 47 | +# Quick |
| 48 | + |
| 49 | +# Step 5.1 -> Create Nano Server Image VHD with IP-Address |
| 50 | + |
| 51 | +Set-Location $destinationDir |
| 52 | +New-NanoServerImage -MediaPath .\ -BasePath C:\Nano -TargetPath .\Images\NanoVM01.vhd -MaxSize 20GB -DeploymentType Guest -Packages $NanoPackages -Edition Datacenter -ComputerName "Nano01" -InterfaceNameOrIndex Ethernet -Ipv4Address "192.168.1.177" -Ipv4SubnetMask "255.255.255.0" -Ipv4Gateway "192.168.1.1" -Ipv4Dns "192.168.1.50" |
| 53 | + |
| 54 | + |
| 55 | +# Better Step 5.1 |
| 56 | + |
| 57 | +$VHDDest = ".\Images\NanoVM01.vhdx" |
| 58 | +$MaxSize = 20GB |
| 59 | +$Edition = "Datacenter" |
| 60 | +$DeploymentType = "Guest" |
| 61 | +# $DriverPath = ".\Drivers" -> -DriverPath $DriverPath |
| 62 | +$MediaPath = "C:\" |
| 63 | +# $BasePath -> bei uns vorher definiert |
| 64 | +$ComputerName = "Nano01" |
| 65 | +$DomainName = "legendary.local" |
| 66 | + |
| 67 | + |
| 68 | +$NanoPackages = "Microsoft-NanoServer-Storage-Package", |
| 69 | +"Microsoft-NanoServer-Compute-Package", |
| 70 | +"Microsoft-NanoServer-DCB-Package", |
| 71 | +"Microsoft-NanoServer-FailoverCluster-Package", |
| 72 | +"Microsoft-NanoServer-DSC-Package", |
| 73 | +"Microsoft-NanoServer-OEM-Drivers-Package" |
| 74 | + |
| 75 | + |
| 76 | +# IP Configuration |
| 77 | +$Ipv4Address = "192.168.1.177" |
| 78 | +$Ipv4SubnetMask = "255.255.0.0" |
| 79 | +$Ipv4Gateway = "192.168.1.1" |
| 80 | +$Ipv4Dns = "192.168.1.50" |
| 81 | + |
| 82 | +# If needed implement some updates -> add "-ServicingPackagePath $ServicingPackagePath" |
| 83 | +# $ServicingPackagePath = ".\updates\xx.cab", ".\Updates\xx.cab" |
| 84 | + |
| 85 | +# If needed unnatend File -> add "-UnattendPath $UnattendFile" |
| 86 | +# $UnattendFile = ".\unattend\unattend.xml" |
| 87 | + |
| 88 | +# Nano Image |
| 89 | +New-NanoServerImage -MediaPath $MediaPath -BasePath $BasePath -TargetPath $VHDDest -DeploymentType $DeploymentType -Edition $Edition -Package $NanoPackages -MaxSize $MaxSize -ComputerName $ComputerName -DomainName $DomainName -InterfaceNameOrIndex Ethernet -Ipv4Address "192.168.1.177" -Ipv4SubnetMask "255.255.255.0" -Ipv4Gateway "192.168.1.1" -Ipv4Dns "192.168.1.50" -ReuseDomainNode -EnableRemoteManagementPort |
| 90 | + |
| 91 | + |
| 92 | +# Step 6 -> Create VM |
| 93 | + |
| 94 | +Copy-Item $destinationDir\Images\NanoVM01.vhdx -Destination C:\VMs |
| 95 | +New-VM -Name NanoVM01 -BootDevice VHD -VHDPath C:\VMs\NanoVM01.vhdx -SwitchName External -Generation 2 |
| 96 | +Start-VM NanoVM01 |
| 97 | + |
| 98 | +############ Step 7.1 VM Management - PowerShell Direct ############ |
| 99 | + |
| 100 | +Enter-PSSession -VMName NanoVM01 #PSDirect |
| 101 | + |
| 102 | +Get-Command -CommandType Cmdlet |
| 103 | + |
| 104 | +############ Step 7.2 VM Management - Remote PSSession ############ |
| 105 | + |
| 106 | +Set-Item WSMan:\localhost\Client\TrustedHosts '192.168.1.177' -Concatenate –Force #Concatenate important not overwrite entries, add |
| 107 | +Get-Item WSMan:\localhost\Client\TrustedHosts |
| 108 | + |
| 109 | +Enter-PSSession -ComputerName 192.168.1.177 -Credential (Get-Credential) |
| 110 | + |
| 111 | +############ Step 7.2 VM Management - PowerSHell CIM-Session (WMI) ############ |
| 112 | + |
| 113 | +$cimIp = "192.168.1.177" |
| 114 | +$user = $DomainName + "\Administrator" |
| 115 | +$cimSession = New-CimSession -Credential $user -ComputerName $cimip |
| 116 | + |
| 117 | +Get-CimInstance -CimSession $cimSession -ClassName Win32_ComputerSystem | Format-List * |
| 118 | +Get-CimInstance -CimSession $cimSession -Query "SELECT * from Win32_Process WHERE name LIKE '%'" |
| 119 | + |
| 120 | + |
| 121 | +# Step 8 Update Management running System |
| 122 | + |
| 123 | +# Enter-PSSession -VMName NanoVM01 #PSDirect |
| 124 | +$cim = New-CimInstance -CimSession $cimSession -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession |
| 125 | +$msUpdates = Invoke-CimMethod -InputObject $cim -MethodName ScanForUpdates -Arguments @{SearchCriteria="IsInstalled=0";OnlineScan=$true} |
| 126 | + |
| 127 | +$installUpdates = Invoke-CimMethod -InputObject $cim -MethodName ApplyApplicableUpdates |
| 128 | +Restart-Computer |
| 129 | + |
| 130 | +############ Add Nano Server Roles ############ |
| 131 | + |
| 132 | +Get-WindowsFeature -ComputerName Nano01 |
| 133 | +Install-WindowsFeature -ComputerName Nano01 -Name Storage-Replica |
| 134 | + |
| 135 | +############ Nano Server PackageProvider ############ #Help: https://github.com/OneGet/NanoServerPackage |
| 136 | + |
| 137 | +Enter-PSSession -ComputerName 192.168.1.177 -Credential (Get-Credential) |
| 138 | + |
| 139 | +# Download PowerShell Module |
| 140 | +Save-Module -Path “$env:ProgramFiles\WindowsPowerShell\Modules” -Name NanoServerPackage -MinimumVersion 1.0.0.0 |
| 141 | + |
| 142 | +# Import PowerShell Module |
| 143 | +Import-PackageProvider NanoServerPackage |
| 144 | + |
| 145 | +# Find Nano Server Package |
| 146 | +Find-NanoServerPackage |
| 147 | +Find-Package -ProviderName NanoServerPackage -DisplayCulture |
| 148 | + |
| 149 | +# Find Specific Nano Server Images |
| 150 | +Find-NanoServerPackage *iis* |
| 151 | + |
| 152 | +Install-NanoServerPackage -Name Microsoft-NanoServer-IIS-Package -Culture en-us -MinimumVersion 10.0.13393.0 |
| 153 | +Restart-Computer |
| 154 | + |
| 155 | +# Get Installed Packages |
| 156 | + |
| 157 | +Get-Package -ProviderName NanoServerPackage |
| 158 | + |
| 159 | +# Get Installed Packages vhd |
| 160 | +Get-Package -ProviderName NanoServerPackage -FromVhd C:\VMs\NanoServer-WIM-14300.1000.vhdx |
| 161 | + |
| 162 | + |
| 163 | +####################### Install DSC on NanoServers ####################### |
| 164 | + |
| 165 | +#Install Nano Server Package Provider and DSC Package on Nodes |
| 166 | +$Nodes = @('Nano01.legendary.local') |
| 167 | +$Nodes | foreach { |
| 168 | + Invoke-Command -ComputerName $_ -ScriptBlock { |
| 169 | + Install-PackageProvider NanoServerPackage -Force |
| 170 | + Import-PackageProvider NanoServerPackage |
| 171 | + Install-package Microsoft-NanoServer-DSC-Package -ProviderName NanoServerPackage -Force |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | + |
| 176 | +########################################################## Break before Container ###################################################### |
| 177 | + |
| 178 | + |
| 179 | +############################# Vorbereiten Host ################################ |
| 180 | + |
| 181 | +#Install Hyper-V |
| 182 | +#Install-WindowsFeature Hyper-V -IncludeAllSubFeature -IncludeManagementTools -Restart |
| 183 | + |
| 184 | +#Install-Container |
| 185 | +#Install-WindowsFeature Containers -IncludeAllSubFeature -IncludeManagementTools -Restart |
| 186 | + |
| 187 | +#Ueberpruefen Prerequisites |
| 188 | +Get-WindowsFeature -Name Hyper-V |
| 189 | +Get-WindowsFeature -Name Containers |
| 190 | + |
| 191 | +# Nach TP5 Docker Management |
| 192 | +# Unstable preRelease PowerShell Docker implementation |
| 193 | +# Register-PSRepository -Name DockerPS-Dev -SourceLocation https://ci.appveyor.com/nuget/docker-powershell-dev |
| 194 | +# Install-Module -Name Docker -Repository DockerPS-Dev -Scope CurrentUser -AllowClobber |
| 195 | + |
| 196 | +Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force |
| 197 | +Install-Module -Name DockerMsftProvider -Force |
| 198 | +Install-Package -Name docker -ProviderName DockerMsftProvider -Force |
| 199 | +Restart-Computer -Force |
| 200 | + |
| 201 | +# docker befehle anschauen |
| 202 | + |
| 203 | +docker help |
| 204 | + |
| 205 | +# Images suchen mit Docker |
| 206 | +docker search Microsoft |
| 207 | + |
| 208 | +# Runterladen NanoServer Image |
| 209 | +docker pull microsoft/nanoserver |
| 210 | +# Runterladen ServerCore Image |
| 211 | +docker pull microsoft/windowsservercore |
| 212 | +# Runterladen NanoServer Image mit IIS |
| 213 | +docker pull microsoft/iis:nanoserver |
| 214 | + |
| 215 | +# FireWall Ports für externes Docker Management Zulassen |
| 216 | +netsh advfirewall firewall add rule name="docker engine" dir=in action=allow protocol=TCP localport=2375 |
| 217 | + |
| 218 | +# Konfiguration Docker Service damit er auf Port 2375 von Extern hört |
| 219 | +Stop-Service docker |
| 220 | +dockerd --unregister-service |
| 221 | +dockerd -H npipe:// -H 0.0.0.0:2375 --register-service |
| 222 | +Start-Service docker |
| 223 | + |
| 224 | +# Docker Version überprüfen |
| 225 | + |
| 226 | +docker version |
| 227 | + |
| 228 | +# Erstellen erster Windows-Container |
| 229 | +docker run -d microsoft/nanoserver cmd.exe |
| 230 | +docker ps -a |
| 231 | + |
| 232 | +# Erstellen erster HyperV-Container |
| 233 | +docker run -d --isolation=hyperv microsoft/nanoserver cmd |
| 234 | + |
| 235 | +################################################# Mit Containern Spielen ################################################# |
| 236 | + |
| 237 | + |
| 238 | +#Container Images Anzeigen |
| 239 | +docker images |
| 240 | + |
| 241 | +#Erste Applikation erstellen |
| 242 | +Enter-PSSession -ContainerName IISWorker01 -RunAsAdministrator |
| 243 | + |
| 244 | +#Entfernen der Default-Site |
| 245 | +del C:\inetpub\wwwroot\iisstart.htm |
| 246 | + |
| 247 | +#Erstellen einer neuen Website |
| 248 | +"Hello World" > C:\inetpub\wwwroot\index.html |
| 249 | + |
| 250 | +#Da war doch noch was, die containerdemo file... |
| 251 | +Get-ChildItem C:\ |
| 252 | + |
| 253 | +#Session Verlassen |
| 254 | +Exit-PSSession |
| 255 | + |
| 256 | +#Stopen des Worker IIS Containers |
| 257 | +Stop-Container -Name IISWorker01 |
| 258 | + |
| 259 | +#Entfernen des Worker IIS Containers |
| 260 | +Remove-Container -Name IISWorker01 -Force |
| 261 | + |
| 262 | +#Entfernen des Manipulierten "Images" |
| 263 | +Remove-ContainerImage -Name WindowsServerCoreIIS -Force -WhatIf |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | +################ Hyper-V Container ################ |
| 268 | + |
| 269 | +#Erstellen eines Hyper-V Containers |
| 270 | +$hvcontainer01 = New-Container -Name HYPVCON01 -ContainerImageName NanoServer -SwitchName "NATSwitch01" -RuntimeType HyperV |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | +################# Docker ################## |
| 275 | + |
| 276 | +docker run -it --isolation=hyperv 646d6317b02f cmd |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | +############################ Docker Ressource Management ########################## |
| 282 | +docker run -it --cpu-shares 2 --name dockerdemo windowsservercore cmd |
0 commit comments