Showing posts with label nano. Show all posts
Showing posts with label nano. Show all posts

Saturday, February 18, 2017

Changing Nano back to DHCP

I've been playing around some more with Nano server, but I didn't want to create yet another VM, so I decided to use one of my existing Nano servers. But it had an IP set already, and was set to an Internal switch (so no internet connectivity possible). So let's PowerShell-fix this!

First let's change the adapter of my VM called nano1:

Get-VM nano1 |Get-VMNetworkAdapter|Connect-VMNetworkAdapter -SwitchName external

There, that didn't hurt so much! Good, now let's change the settings inside the nano1 VM, to set the IP's back to DHCP. First, this very cool thing in Hyper-V called PowerShell Direct, allows me to enter the VM without needing any IP connectivity. All you need is the credentials of the VM, and to select the "-VMName" option with Enter-PSSession:

$cred = Get-Credential
Enter-PSSession -VMName nano1 -Credential $cred

This is what it looks like:

PS C:\> $cred = Get-Credential
Enter-PSSession -VMName nano1 -Credential $cred
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
[nano1]: PS C:\Users\administrator\Documents>

As Montgomery Burns says: "Excellent...": Did you notice the [nano1] in front of the last prompt? We're inside the VM! BTW, you don't need to add the credential, it will ask you for the credentials if you don't add them, but if you go in and out more than once, this is nicer.

Now that we're in a session, let's change the IP address and DNS back to DHCP enabled:

Get-NetIPAddress -InterfaceAlias "Ethernet" | Set-NetIPInterface -Dhcp Enabled
Set-DnsClientServerAddress -ResetServerAddresses -InterfaceAlias Ethernet

Done!

Saturday, January 28, 2017

Adding a Windows Nano server to the domain


In my previous article, I created a Nano server image. This one is about adding the Nano server to a domain. Adding Nano servers to a domain isn't a pretty little single cmdlet like many others are, but consists of a list of things to do:

  • Configure DNS on the Nano server
  • Create what's called a blob file on a DC (or a machine that is joined to the domain, and a user that has rights to add a computer to the domain or as a Domain admin user)
  • Copy the file over to the Nano server
  • Use the blob file to add the server to the domain
  • Reboot
I've found the following code on petri.com site, with an ingenious way to copy the blob file over. If you have the Storage package installed, you can of course just copy it using a share like \\nanosrv1\c$


#Set dns for Nano server
netsh interface ip set dnsservers name="Ethernet" static 10.0.0.4 primary


#Create domain blob file
djoin.exe /provision /domain mydomain.int /machine nanosrv1 /savefile c:\temp\odjblob


#get file over to nano server, needs trustedhosts first
Set-Item WSMan:\localhost\Client\TrustedHosts  "10.0.0.5" -Concatenate


#trick from https://www.petri.com/join-windows-server-2016-nano-domain
#to copy the blob over to the target server
$filePath = 'c:\temp\odjblob'
$fileContents = Get-Content -Path $filePath -Encoding Unicode
$session = New-PSSession -ComputerName 10.0.0.5 -Credential nanosrv1\username
Invoke-Command -Session $session -ArgumentList @($filePath,$fileContents) -ScriptBlock {
    param($filePath,$data)
    New-Item -ItemType directory -Path c:\temp
    Set-Content -Path $filePath -Value $data -Encoding Unicode
}


#Now add the nano to the domain with the blobfile
djoin /requestodj /loadfile c:\temp\odjblob /windowspath c:\windows /localos
shutdown /r

It is a bit convoluted, but once you get the hang of it, it is doable..

Creating a Nano Server Image

Installing Windows 2016 Nano server isn't simply adding the DVD and clicking next-next-finish, but it needs some preparation. The base nano image wim file is only 168MB, but that has no functionality in itself. More needs to be added through features, drivers and packages.

From a management workstation, mount the Windows 2016 ISO (i.e. doubleclick it, take note of the driveletter). On the ISO file you will see a NanoServer directory:


That directory has the NanoServer.wim file, Packages folder and a NanoServerImageGenerator folder. That last folder contains a PowerShell Module, which you need to import in an Administrator PowerShell window (which in my case is on the E: drive):

Import-Module E:\NanoServer\NanoServerImageGenerator\NanoServerImageGenerator.psm1

Now you should have a bunch of extra commands available:

PS C:\Users\Akos> get-command -Module *nano* | select Name

Name                
----                
Edit-NanoServerImage
Get-NanoServerPackage
New-NanoServerImage  

The New-NanoServerImage cmdlet is the one you will need to create a fully functional image. The options are a slew of information. I've created a splatted variable set below, otherwise the line becomes far too long for the blog ;-)

$Pwd = ConvertTo-SecureString -String "Pa$$w0rd!" -AsPlainText -Force

$Options = @{
    MediaPath = 'E:' #Location of DVD
    BasePath = 'D:\TMP\Base' #Location of install files
    TargetPath = 'D:\TMP\NanoWeb01.vhdx' #Where the vhdx will come
    ComputerName = 'NanoWeb01' #No idea, I think the computername..
    AdministratorPassword = "$Pwd" #A secure string password
    DeploymentType = 'Guest' #This will make it a vhdx file
    Edition = 'Standard' #Windows version (Standard or Datacenter)
    Package = 'Microsoft-NanoServer-IIS-Package' #Packages, in this case IIS
}

New-NanoServerImage -EnableRemoteManagementPort -Storage @Options

This example creates a VM called NanoWeb01, with a password of "Pa$$w0rd!", and has IIS installed. The switch "-EnableRemoteManagementPort" does what it says. You can then connect to it via PSRemoting. The switch "-Storage" allows the Nano server to have filesharing available. If you don't need that, you can let it go, but for testing it's nice to have. This VM is ready for Hyper-V, and is about 560MB as it is configured like this.

There are several packages you can choose from, which can be found by the Get-NanoServerPackage cmdlet:

PS C:\Users\Akos> Get-NanoServerPackage -MediaPath e:
Microsoft-NanoServer-Compute-Package
Microsoft-NanoServer-Containers-Package
Microsoft-NanoServer-DCB-Package
Microsoft-NanoServer-Defender-Package
Microsoft-NanoServer-DNS-Package
Microsoft-NanoServer-DSC-Package
Microsoft-NanoServer-FailoverCluster-Package
Microsoft-NanoServer-Guest-Package
Microsoft-NanoServer-Host-Package
Microsoft-NanoServer-IIS-Package
Microsoft-NanoServer-OEM-Drivers-Package
Microsoft-NanoServer-SCVMM-Compute-Package
Microsoft-NanoServer-SCVMM-Package
Microsoft-NanoServer-SecureStartup-Package
Microsoft-NanoServer-ShieldedVM-Package
Microsoft-NanoServer-SoftwareInventoryLogging-Package
Microsoft-NanoServer-Storage-Package

Next to this there are other switches too, of which a complete list and more info can be found on Microsoft's site. In all, Nano server takes a little work to get it running, but once it does, it starts in seconds.

Edit: You may have noticed the -Storage and -EnableRemoteManagementPort switches in my New-NanoServerImage command. I just saw in a different article, you can put them in the splatted options as well, by doing "Storage = $true" and the same for EnableRemoteManagementPort. You learn something new every day..