Social

tirsdag den 24. maj 2016

Script for deploying Nano Server (TP5)

There are plenty of scripts around that helps deploying Nano server. But there seems to be issues between the various TPs, I had trouble with a script that worked for TP4 but not at all for TP5.

So I ended up creating my own. It should just run in one go, but I suggest you take a few lines at at time to sort out any issues.

The script as follows, and found on Technet gallery.


 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# note this is written for Server 2016 TP5 - it probably doesn't work on other TPs

# create this folder and copy the NanoServerImageGenerator from the 2016 media
cd D:\NanoServer

Import-Module .\NanoServerImageGenerator\NanoServerImageGenerator.psm1


$BasePath = "D:\NanoServer"
$TargetPath = "$BasePath\Nano01.vhd"
$ComputerName = "Nano01"
$Password = ConvertTo-SecureString -AsPlainText -String "Password" -Force

$IPAddress = "192.168.0.42"
$GatewayAddress = "192.168.0.1"
$DNSAddresses = ('192.168.0.21','8.8.8.8')
$Ipv4SubnetMask = "255.255.255.0"

$Domain = 'my.domain'

$Parameters = @{
    DeploymentType = 'Guest'
    Edition = 'Datacenter'
    MediaPath = "E:\"
    BasePath = $BasePath
    TargetPath = $TargetPath
    ComputerName = $ComputerName
    AdministratorPassword = $Password
    Ipv4Address = $IPAddress
    Ipv4SubnetMask = $Ipv4SubnetMask
    Ipv4Gateway = $GatewayAddress
    Ipv4Dns = $DNSAddresses
    InterfaceNameOrIndex = "Ethernet"
}

New-NanoServerImage @Parameters -ErrorAction Stop

# credentials for the nano server
$User = "$IPAddress\Administrator"
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password

# add it to trusted hosts
Set-Item WSMan:\localhost\Client\TrustedHosts -Value $IPAddress -Force -Concatenate

# size of the vhd - WOW!
[int]((Get-ChildItem -Path $TargetPath).Length / 1MB)

# can only install IIS and SCVMM offline
Find-NanoServerPackage *iis* | Install-NanoServerPackage -Culture 'en-us' -ToVhd $TargetPath -Verbose
Find-NanoServerPackage *scvmm* | Install-NanoServerPackage -Culture 'en-us' -ToVhd $TargetPath -Verbose

# create a new VM
$VMName = "Nano01"
New-VM -Name $VMName -MemoryStartupBytes 512MB -SwitchName MGMT -VHDPath $TargetPath -Generation 1 -Verbose

# and start it
Start-VM -Name $VMName

# we wait - first boot can be "slow" :D
Write-Verbose "waiting abit for VM to boot for the first time..."
Start-Sleep -Seconds 20

# need to run this with administrative priviliges in the domain
djoin.exe /provision /domain $Domain /machine $ComputerName /savefile .\"$ComputerName.txt"

# create session object
$Session = New-PSSession -ComputerName $IPAddress -Credential $Credential

# copy domain join blob file to nano server
Copy-Item -ToSession $Session -Path .\"$ComputerName.txt" -Destination "c:\"

# enter the session
Enter-PSSession -Session $Session

# domain join nano server
djoin /requestodj /loadfile c:\$env:COMPUTERNAME.txt /windowspath c:\windows /localos

# and do a restart
Restart-Computer

# wait for restart

# need to create a new session after it restarts - and we will use domain credentials
$User = "$Domain\Administrator"
$Password = ConvertTo-SecureString "domainadminpassword" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Password

$Session = New-PSSession -ComputerName $IPAddress -Credential $Credential

# enter the session
Enter-PSSession -Session $Session

# install the nano server package provider

Install-PackageProvider NanoServerPackage
Import-PackageProvider NanoServerPackage

Find-NanoServerPackage

mandag den 2. maj 2016

Automated module installation to Azure Automation

Ever needed to install a bunch of modules to an Azure Automation Account? This script can do it for you. Only thing you need to do is point it at the ARM-template that deploys the module. These templates are easy to obtain by following the description in the script-file. A simple loop can install multiple modules (example on how in the file).

Get it while it's hot.

Søg i denne blog