Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How it works...

To get ready for this recipe, create the computer account for NANO2 in the RESKIT domain using the djoin command to create the domain blob file. You store this blob in the blob file NANO2.djoin.

In step 1, you review the installed package providers. Note that if NanoServerPackage provider is missing, you need to install this package provider to continue:

In step 2 and step 3, you list the available PackageManagement package providers, noting the NanoServerPackage package, then install this package provider:

In step 4, you view the commands associated with the NanoServerPackage. While these commands are specific to this package, they are wrapper cmdlets for similarly named PackageManagement cmdlets that can be viewed with Get-Command -Noun Package:

In step 5, you view the available packages for Nano Server. Note that some of these packages are installed using switch parameters in the New-NanoServerImage cmdlet, for example, the -DeploymentType Guest switch installs the Microsoft-NanoServer-Guest-Package:

In step 6, you define $InstallPackages as an array of the desired packages:

In step 7 and step 8, you define the path to the server installation media, and to the NanoServerImageGenerator module folder:

In step 9, you import the NanoServerImageGenerator module and view the modules commands:

In step 10 and step 11, you define paths required for the Nano Server base image, VM name, folder, and file path. There is no output from these steps.

In step 12, you define the path to the domain join file that you created in the Getting ready section:

In step 13, define the networking configuration for the VM. Note the $IPV4DNS is an array with two values storing the primary and secondary DNS server IP addresses:

In step 14, you define and view a hash table variable holding all the parameters required in the next step:

In step 15, you run the New-NanoServerImage using splatting to pass the required parameters. Answer the prompt for an administrator password, and review the progress of the creation of the new Nano Server image. Once complete, results are available for review in a time stamped folder under C:\NanoBaseLogs:

In step 16, view the available Hyper-V switch names, and choose the one to associate with your new VM:

In step 17, you create the new VM, and pipe it to Start-VM to start it: