Contact

Subscribe via Email

Subscribe via RSS

Categories

Creative Commons Attribution 4.0 International License
© Rakhesh Sasidharan

Elsewhere

Fixing “The DNS server was unable to open Active Directory” errors

For no apparent reason my home testlab went wonky today! Not entirely surprising. The DCs in there are not always on/ connected; and I keep hibernating the entire lab as it runs off my laptop so there’s bound to be errors lurking behind the scenes.

Anyways, after a reboot my main DC was acting weird. For one it took a long time to start up – indicating DNS issues, but that shouldn’t be the case as I had another DC/ DNS server running – and after boot up DNS refused to work. Gave the above error message. The Event Logs were filled with two errors:

  • Event ID 4000: The DNS server was unable to open Active Directory.  This DNS server is configured to obtain and use information from the directory for this zone and is unable to load the zone without it. Check that the Active Directory is functioning properly and reload the zone. The event data is the error code.
  • Event id 4007: The DNS server was unable to open zone <zone> in the Active Directory from the application directory partition <partition name>. This DNS server is configured to obtain and use information from the directory for this zone and is unable to load the zone without it. Check that the Active Directory is functioning properly and reload the zone. The event data is the error code.

A quick Google search brought up this Microsoft KB. Looks like the DC has either lost its secure channel with the PDC, or it holds all the FSMO roles and is pointing to itself as a DNS server. Either of these could be the culprit in my case as this DC indeed had all the FSMO roles (and hence was also the PDC), and so maybe it lost trust with itself? Pretty bad state to be in, having no trust in oneself … ;-)

The KB article is worth reading for possible resolutions. In my case since I suspected DNS issues in the first place, and the slow loading usually indicates the server is looking to itself for DNS, I checked that out and sure enough it was pointing to itself as the first nameserver. So I changed the order, gave the DC a reboot, and all was well!

In case the DC had lost trust with itself the solution (according to the KB article) was to reset the DC password. Not sure how that would reset trust, but apparently it does. This involves using the netdom command which is installed on Server 2008 and up (as well as on Windows 8 or if RSAT is installed and can be downloaded for 2003 from the Support Tools package). The command has to be run on the computer whose password you want to reset (so you must login with an account whose initials are cached, or use a local account). Then run the command thus:

Of course the computer must have access to the PDC. And if you are running it on a DC the KDC service must be stopped first.

I have used netdom in the past to reset my testlab computer passwords. Since a lot of the machines are usually offline for many days, and after a while AD changes the computer account password but the machine still has the old password, when I later boot up the machine it usually gives are error like this: “The trust relationship between this workstation and the primary domain failed.”

A common suggestion for such messages is to dis-join the machine from the domain and re-join it, effectively getting it a new password. That’s a PITA though – I just use netdom and reset the password as above. :)

 

Windows Server 2012 licensing

I have been catching up on a lot of MVA courses lately and one of them mentioned a short course on Server 2012 licensing so I checked that out yesterday.

The first half of the course made sense to me but the second half didn’t. Mainly coz I haven’t worked with Server & Cloud Enrollment (SCE) and the course assumes you are aware of it, so it only talks about the improvements with Server 2012 R2. From the first half here are some salient points:

  • Server 2012 R2 has four editions. Two of these are for small business (less than 25 & 15 users). Two of these are for private clouds.
    • The private cloud editions are Windows Server 2012 R2 Datacenter and Windows Server 2012 R2 Standard. 
    • The small business editions are Windows Server 2012 R2 Essentials and Windows Server 2012 R2 Foundation.
  • Unlike Server 2008 where the three private cloud editions – Standard, Enterprise, and Datacenter – had differing features, now Standard and Datacenter have the same features. They only differ in terms of virtual instance licenses (i.e. the number of times you can use the license as a virtual server).
    • Standard has two virtual instance licenses.
      • Worth noting that these virtual licenses can be stacked. That is if you attach two licenses to a server then you get 2+2 = 4 virtual licenses. 
      • If you have multiple licenses, when you step up from Standard to Datacenter via the Software Assurance program you can only exchange one Standard license for a Datacenter license. Meaning, you can’t step up two Standard licenses for one Datacenter licenses. It’s a one-t0-one upgrade. 
    • Datacenter has unlimited virtual instance licenses. (This explains why all the Microsoft training centers use Datacenter! No need to worry about guest OS licensing then.)
  • Also, in Server 2008 Datacenter was licensed per processor, while Enterprise and Standard were licensed per server. But in Server 2012 R2 both Standard and Datacenter are licensed per processor.
    • A single license covers up to two processors on a single server. 
  • In contrast Server 2012 R2 Foundation and Essentials are licensed per server. 
    • Essentials is licensed per server for a maximum of two processors.
    • Foundation is licensed per server for a maximum of one processor. 
  • Unlike Server 2008, both versions of Server 2012 – Data Center and Standard – have the same features. Only difference is in terms of virtualization. The Data Center edition supports unlimited virtual guests, the Standard edition only supports two.
  • In addition to the licensing above, you also need device or user Client Access Licenses (CALs). 

Creating a Server 2012 Failover Cluster for iSCSI target

This post is about setting up a Server 2012 R2 failover cluster that acts as an iSCSI target server.

I have four servers: WIN-DATA01, WIN-DATA02, WIN-DATA03, WIN-DATA04. I will be putting WIN-DATA03 & WIN-DATA04 in the cluster. As you know clusters required shared storage so that’s what WIN-DATA01 and WIN-DATA02 is for. In a real world setup WIN-DATA01 & WIN-DATA02 are your SAN boxes whose storage you want to make available to clients. Yes you could have clients access the two SAN boxes directly, but by having a cluster in between you can provide failover. Plus, Windows now has a cool thing called Storage Pools which let you do software RAID sort of stuff.

Prepare the iSCSI target server

First step, prepare the iSCSI target servers that will provide storage for the cluster. The steps for this are in my previous post so very briefly here’s what I did:

Repeat the above for the other server (you can login to that server and issue commands, or do remotely like I did below). Everything’s same as above except for the addition of the -ComputerName switch.

Excellent!

Now let’s move on to the two servers that will form the cluster.

Add shared storage to the servers

Here we add the two iSCSI targets created above to the two servers WIN-DATA03 & WIN-DATA04.

Login to one of the servers, open Server Manager > Tools > iSCSI Initiator.

Targets

Easiest option is to enter WIN-DATA01 in the Target field and click Quick Connect. That should list the targets on this server in the Discovered targets box. Select the ones you want and click Connect.

Another option is to go to the Discovery tab.

Discovery tab

Click Discover Portal, enter the two server names (WIN-DATA01, WIN-DATA02), refresh (if needed), and then the first tab will automatically show all targets on these two servers. Select the ones you want and click Connect as before.

The GUI sets these connections as persistent (it calls them “Favorite Target”) so they are always reconnected when the server reboots.

You can also use PowerShell to add these connections though that isn’t as easy as this point and click. Instructions are in my earlier post so here they are briefly:

Unlike the GUI, PowerShell does not mark these targets as persistent so I have to specify that explicitly when connecting.

Prepare the shared storage

The shared storage we added is offline and needs to be initialized. You can do this via the Disk Management UI or using PowerShell as below. The initializing bits need to be done on any one server only (WIN-DATA03 or WIN-DATA04) but you have to make the disks online on both servers.

Create the cluster

Login to one of the servers that will form the cluster, open Server Manager, go to Tools > Failover Cluster Manager and click Create Cluster on the right side (the Actions pane). This launches the Create Cluster Wizard.

Click Next on the first screen, enter the server names on the second …

Adding Servers to Cluster

… do or don’t do the validation tests (I skipped as this is a lab setup for me), give a name for the cluster and an IP address, confirm everything (I chose to not add all eligible storage just so I can do that separately), and that’s it.

Couple of things to note here:

  • If your cluster servers don’t have any interfaces with DHCP configured, you will also be prompted for an IP address. Otherwise a DHCP address is automatically assigned. (In my case I had an interface with DHCP).
  • A computer object with the cluster server name you specify is created in the same OU as the servers that make up the cluster. You can specify a different OU by giving the full name as the cluster name – so in the example above I would use “CN=WIN-CLUSTER01,OU=Clusters,OU=Server,DC=rakhesh,DC=local” to create the object in the Clusters OU within the Servers OU. Would have been good if the wizard mentioned that.
  • Later, when you add roles to this cluster server, it creates more virtual servers automatically. These are placed in the same OU where the cluster server object is so you must give this object rights to add/ remove computers in that OU. So it’s best you have a separate OU which you can delegate rights to. I used the Delegation Control Wizard to give the WIN-CLUSTER01 object full control over Computer Objects in the rakhesh.local/Servers/Clusters OU.

    5

Instead of the Create Cluster Wizard one can use PowerShell as below:

Configuring the cluster

A cluster has many resources assigned to it. Resources such as disks, networks, and its name. These can be seen in the summary page of the cluster or via PowerShell.

Cluster Resources

Network

I am interested in changing the IP address of my cluster. Currently it’s taken an IP from the DHCP pool and I don’t want that. Being a lab setup both my servers had a NAT interface to connect to the outside world and so the cluster is currently picking up an IP from that. I want it to use the internal network instead.

If I right click on IP address resource I can change it.

IP Address

In my case I don’t want to use this network itself so I have to go to the Networks section in the UI …

Networks

… where I can see there are two networks specified, with one of them having no cluster use while the other is configured for cluster & client use, so I right click on the first network and …

Network Settings

… enable it for cluster access, then I right click on the second network and …

Network Settings

… rename it (for my reference) as well as disable it from the cluster.

Now if I go to the resources section and right click the IP address, I can select the second network and assign a static IP address.

Here’s how to do the above via PowerShell.

To change the network name use the Get-ClusterNetwork to select the network you want (the result is an object) and directly assign the new name as a value:

One would expect to be able to set IP addresses too via this, but unfortunately these are read-only properties (notice it only has the get method; properties which you can modify will also have the set method):

To set the IP address via PowerShell we have to remember that we went to the Cluster Resource view to change it. So we do the same here. Use the Get-ClusterResource cmdlet.

That doesn’t totally help. What we need are the parameters of the resource, so we pipe that to the Get-ClusterParameter cmdlet.

Perfect! And to modify these parameters use the Set-ClusterParameter cmdlet.

To take the Cluster IP Address resource offline & online use the Stop-ClusterResource and Start-ClusterResource cmdlets:

Although it doesn’t say so, you have to also stop and start the Cluster Name resource for the name to pick up the new IP address.

Lastly, to change whether a particular network is used for cluster communication or not, one can do the same technique that was used to change the host name. Just use the Role property. I am not sure what the values for it are, but from my two networks I can see that a value of 0 means it is not used for cluster communication, while a value of 3 means it is used for cluster communication and client traffic.

The GUI is way easier than PowerShell for configuring this network stuff!

Storage (Disks)

Next I want to add disks to my cluster. Usually all available disks get added by default, but in this case I want to do it manually.

Right click Failover Cluster Manager > Storage > Disk and select Add Disk. This brings up a window with all the available disks. Since this is a cluster not every disk present on the system can be used. The disk must be something visible to all members of the cluster as it is shared by them.

Add Disk

Via PowerShell:

To add these disks to the cluster pipe the output to the Add-ClusterDisk cmdlet. There’s no way to select specific disks so you must either pipe the output to a Where-Object cmdlet first to filter the disks you want, or use the Get-Disk cmdlet (as it lets you specify a disk number) and pipe that to the Add-ClusterDisk cmdlet.

(I won’t be adding these disks to my cluster yet as I want to put them in a storage pool. I’ll be doing that in a bit).

Quorum

Quorum is a very important concept for clusters (see an earlier post of mine for more about quorum).

The cluster which I created is currently in the Node Majority mode. (Because I haven’t added and Disk or File Share witnesses to it). That’s not a good mode to be in so let’s change that.

Go to the Configure Cluster Quorum Settings as in the screenshot below, click Next …

Quorum

… choose the second option (Select the quorum witness) and click Next …

Witness

… in my case I want to use a File Share witness so I choose that option and click Next …

File Witness

… create a file share someplace, point to that, and click Next …

File Share

… click Next and then Finish.

Now it’s configured.

Storage (Pool)

(If you plan to create a storage pool add an extra shared disk to your cluster. I created a new target on the WIN-DATA02 & WIN-DATA01 server (no need for doing on both but I just did so it’s consistent), mapped another virtual disk to it, and used the iSCSI initiator on WIN-DATA03 & WIN-DATA04 to map it. Storage Pools on Failover Clusters require a minimum of three disks).

I want to use Storage Spaces (they are called Storage Pools in Failover Cluster Manager). Storage Spaces is a new feature in Server 2012 (and Windows 8) and it lets you combine disks and create virtual disks on them that are striped, mirrored, or have parity (think of it as software RAID).

We can create a new Storage Pool by right clicking on Failover Cluster Manager > Storage > Pools and select New Storage Pool.

Pool

Click Next, give the Pool a name …

Pool Name

… select the disks that will make up the pool (notice that the disks shown below are the iSCSI disk that are visible to both nodes; neither disk is actually on the local computer, they are both from a SAN box someplace (in this case the WIN-DATA01 & WIN-DATA02 servers from where we created these before) …

Pool Disks

… and click Create.

Right click on the pool that was created and make virtual disks on that. These virtual disks are software RAID equivalents. (The pool is a placeholder for all your disks. The virtual disks are the logical entities you create out of this pool). Here’s the confirmation page of the pool I created:

Pool Virtual Disk

Once the disk is created, be sure to not uncheck the “Create a volume when this wizard closes” check box. If you did uncheck, you’ll have to go to Server Manager > File and Storage Services > Volumes, click on TASKS and select New Volume. The virtual disk is just a disk, what we have to do now is create volumes on it.

Below is a screenshot of the volume I created. I chose ReFS for no particular reason, and assigned the full space to the volume. Also, the screenshot shows that I didn’t assign a drive letter. That’s incorrect. I did just that I forgot to do that when taking this screenshot. (Note that I assigned the drive letter R. This will be used later).

Volume

Via PowerShell:

As with the GUI, once the disk is created a cmdlet has to be run to create a volume on the disk. It’s probably the New-Volume cmdlet, but it’s throwing errors in my case and I am too tired to investigate further so I’ll skip it for now.

Add Roles

Finally lets add the iSCSI target server role.

Right click Failover Cluster Manager > Roles and select Configure Roles.

Click Next, select iSCSI Target Server, and click Next. This steps assumes the iSCSI Target Server role is installed on both nodes of the cluster. If not, install it via Server Manager or PowerShell.

Give the role (the virtual server that hosts the role) a name and IP address …

ISCSI Target Server

… select storage (the previously created volume; if you missed out on creating the volume go back and do it now), click Next, Next, and that’s it.

At this point it’s worth taking a step back to understand what we have done. What we did just now is create a virtual server (a role in the cluster actually) and assigned it some storage space. One might expect this storage to be the one that’s presented by the iSCSI server as a target, but no, that’s not the case. Think of this server and its storage as similar to the WIN-DATA01 and WIN-DATA02 servers that we dealt with initially. What did we do to set these as an iSCSI target? We created a target, created virtual iSCSI disks, and assigned mappings to them. That’s exactly what we have to do here too!

Ideally one should be able to use the GUI and do this, but Server Manager seems to have trouble communicating with the newly created WIN-DATA server. So I’ll use PowerShell instead.

And that’s it! Now I can add this target back to the WIN-DATA01 & WIN-DATA02 servers if I want (as those are the Initiator IDs I specified) and whatever I write will be written back to their disks via this clustered iSCSI target. I am not sure if the mirroring will happen across both servers though, but this is all just for fun anyways and not a real life scenario.

Lastly …

Before I conclude here’s something worth checking out.

The WIN-DATA virtual server is currently on the WIN-DATA04 node. This means WIN-DATA04 is the one who is currently providing this role, WIN-DATA03 is on standby.

If I login to WIN-DATA04 and check its disks I will see the mirrored volume I created:

If I do the same on WIN-DATA03 I won’t see the volume.

If I right click on the role in Failover Cluster Manager, select Move > Select Node, and select the new node as WIN-DATA03, then this becomes the new active node. Now if I check the volumes and disks of both servers the information will be the other way around. WIN-DATA03 will have the volume and disk, WIN-DATA04 won’t have anything!

This is how clustering ensures both servers don’t write to the shared storage simultaneously. Remember, the shared storage is just a block device. It doesn’t have any file locking nor is it aware of who is writing to it. So it’s up to the cluster to take care of all this.

Also …

Be sure to add WIN-CLUSTER01 and WIN-DATA to DNS with the correct IPs. If you don’t do that Server Manager and other tools won’t be able to resolve the name.

There’s more …

This post is just a tip of the iceberg. There’s so many more cool things you can do with iSCSI, Clustering, and Storage Spaces in Server 2012 so be sure to check these out elsewhere!

Server 2012 add/ remove initiator IDs for an iSCSI target

Once you create an iSCSI target on Windows Server 2012 there doesn’t seem to be a way to add/ remove initiator IDs via the GUI. But you can use PowerShell for it. Set-IscsiServerTarget is your friend.

Bear in mind this replaces the existing list with the new one.

A cool thing about most of these iSCSI cmdlets is that they work remotely too. So one can add a -ComputerName xxx switch to work with a remote computer.

Notes on iSCSI and Server Core 2012

For the Initiator (client)

Prerequisites

  1. Be sure to enable the enable the MSiSCSI service and set its startup type to Automatic.

  2. Ensure the iSCSI initiator outgoing & incoming rules are allowed on the firewall.

Connecting to a Target

To connect to a target you have to connect to a target portal first. The portal lets you enumerate the targets available.

After connecting, list the targets thus:

Do this for each portal you are aware of:

Note that Get-IscsiTarget now lists targets from all the portals.

To connect to a specific target, use the Connect-IscsiTarget cmdlet:

Viewing the disks

To view the disks available, use the Get-Disk cmdlet.

Numbers 2 & 3 are the iSCSI disks.

As far as the OS is concerned these are regular disks. To use them: 1) Change their status to online, 2) Initialize the disk, and 3) Partition & Format.

If you have many disks (physical or via iSCSI) you can also use the Get-IscsiConnection and Get-IsciSession to select just the iSCSI connections you want, and filter these to the Get-Disk cmdlet.

Making a session persistent across reboots

By default iSCSI connections are not persistent across reboots (note the IsPersistent : False above). To make a connection persistent there area two options:

  1. When connecting to the iSCSI target the first time use the -IsPersistent switch.

  2. If you want to make an existing session persistent, pipe it to the Register-IcsiSession cmdlet.

To make a session non-persistent, pipe it to the Unregister-IscsiSession cmdlet.

Disconnecting a Target

If you would like to disconnect a session use the Disconnect-IscsiTarget cmdlet.

For the Target (server)

  1. Create a Target.

    When creating the target it is very important to specify the initiator IDs. The cmdlet doesn’t prompt for these if you don’t mention (unlike the UI which doesn’t go ahead unless initiator IDs are specified). If the initiator IDs are missing no one can see this target.

    Initiator IDs can be specified via IQNs, IP addresses, IPv6 addresses, DNS name, and MAC addresses. Notice the ‘IPN:xxx’ bit above? Replace IQN with IPAddress, IPv6Address, DNSName, and MACAddress if you are specifying initiator IDs using these, followed by the address or name. For instance:

    If there’s only one initiator ID it can be specified as it is. If there multiple, separate them with commas. There’s no need to put them inside @(…) as above – that’s just to make it explicit to the reader that the input is an array. Separating by commas will have the same effect irrespective of the @(…) notation.

    It’s also worth pointing out that if multiple initiators are allowed to access a target, they will all be able to read/write to the target, but expect corruption. There are exceptions of course.

  2. Create an iSCSI virtual disk which will back the LUN presented by the target.

  3. Create multiple virtual disks if needed.
  4. Map these virtual disks to the target.

And that’s it. Initiators can now connect to the target. In the example above, since the target has two LUNs, initiators will see two disks after connecting.

Cloning Server Core 2012 using VMware Workstation

Pretty straightforward, but it’s not obvious whether cloning the machine will also sysprep. It does not. So after cloning the machine, don’t forget to sysprep it.

  1. Ensure the VM is powered off.
  2. Right click the VM > Manage > Clone.
  3. The cloning wizard is launched. Go ahead with it. I chose the full clone option.
  4. After cloning power up the machine. At this point it is identical to the original so it’s best the original is kept powered off to avoid any conflicts.
  5. Login to the machine, go to C:\Windows\System32 run sysprep.exe. Keep the default system cleanup action but click Generalize so the SIDs etc are recreated. I selected to reboot under Shutdown Options.
  6. That’s pretty much it. Upon reboot you are given the option of logging in with the local accounts; upon logging in you have to change the password.
  7. Now set the IP, name, etc as usual. Enjoy!

These instructions apply to all versions of Windows. Server Core 2012 is just what I used it with.

Initial Server 2012 Core configuration using PowerShell

Just for future reference to myself.

  1. Install Server Core 2012 as usual.
  2. Login. Change the IP address thus:
  3. Specify DNS server addresses:
  4. Rename the computer:
  5. Restart the computer so the name change takes effect.
  6. Update: Rename the computer & join the domain (thanks to Daniel Streefkerf (check out his blog, if you like my blog posts you’ll surely enjoy his!) for pointing this out – since PowerShell 3.0 the Add-Computer cmdlet has a -NewName switch that lets you rename and add/ move a computer):

Update: If you want to do NIC teaming, do the following after step 1.

Now continue with assigning IP address etc, but use the newly created Team adapter instead.

Get-WindowsFeature missing

I always open up PowerShell on $randomcomputer and type Get-WindowsFeature expecting to get a list of Windows features. Sometimes it doesn’t work and then I Google on why that’s the case, forgetting that I’ve been down this route umpteen times. So here’s a post for myself.

The *-WindowsFeature cmdlets are available via the Server Manager module which in turn is either present by default (on servers) or installed via the Remote Server Admin Tools (on clients).

  1. Windows Server 2012: Modules are loaded automatically on demand so the *-WindowsFeature cmdlets are available without any additional steps.
  2. Windows Server 2008 R2: Import the Server Manager module and then the *-WindowsFeature cmdlets can be used.
  3. Windows 8: Install the Server Manager via RSAT. This makes the Server Manager module available for automatic loading and then the *-WindowsFeature cmdlets can be used. Windows 8 also provides (Get|Enable|Disable)-WindowsOptionalFeature cmdlets as part of the DISM module (which is present by default). These provide similar functionality to the *-WindowsFeature cmdlets (doesn’t work on remote computers though!). Add the -Online when using these cmdlets as they can work with the running instance or a mounted Windows image.
  4. Windows 7: Installing the Server Manager via RSAT doesn’t help. It doesn’t include the Server Manager module and so the *-WindowsFeature cmdlets are not available. An alternative is to install the 3rd party Client Manager module which gives the *-ClientFeature cmdlets.

Managing BitLocker disks on Server Core

I have a Server Core 2012 that has two BitLocker encrypted disks on it. When I encrypted those disks the server had the full GUI but after I converted to Core there’s obviously no GUI to just double click and be prompted for a password etc. So need to use the command line tools.

There seems to be two ways.

First are the BitLocker command line tools. Manage-bde looks like the most useful command here. Using this one can see the status of all the drives on the machine, lock, unlock, set auto-lock auto-unlock, and also turn on or off BitLocker encryption on a drive.

Typing manage-bde in the command prompt gives you all the options. Each of these options have further switches which you can discover by typing manage-bde <option-name> -?.

To view the status of all drives on the machine:

To unlock an encrypted drive (with drive letter D:) to use with the system:

I use passwords, hence the -pw switch. If you use recovery keys or certificates there are switches for that too. manage-bde prompts for a password and unlocks the drive, mounting it on the specified drive letter.

To set the drive (with drive letter D:) as auto-unlocked:

That’s all. From now on the drive will be automatically unlocked when attached to the system.

The syntax for disabling auto-unlock and locking a drive are pretty obvious from the examples above. The thing to remember is you always specify the manage-bde command followed by a dash switch specifying what you want to do, and after that you specify the drive letter.

There are two other commands: Repair-Bde for repairing corrupted BitLocker encrypted drives and BdeHdCfg for setting up a drive with BitLocker encryption (though it doesn’t seem to be required any more as Manage-Bde includes some of this functionality).

Apart from the BitLocker command line tools you can also manage BitLocker via PowerShell. This is only for Windows 8/ Windows Server 2012 and is available via the BitLocker module (requires RSAT on Windows 8).

To view the available drives on a system and their BitLocker status do:

You can also check the status of a specific drive with the above cmdlet by passing it the drive letter with the -MountPath switch.

To unlock a BitLocker drive (with letter D:) do:

The cmdlet does not prompt for a password. You have to pass it via the -Password switch. You can’t pass the password as plain text either, so have to convert it to a secure string. Use the ConvertTo-SecureString cmdlet for that or just use Read-Host and convert the inputted text to secure string on the fly.

To set auto-unlock on a drive (with letter D:) do:

Similar cmdlets exist for locking and auto-locking drives.

After writing this post I discovered a TechNet article that goes into more detail on the above command line tools and cmdlets. Go check it out.

DISM in Windows Server 2012 (part 1)

After writing yesterday’s post I wondered what switches DISM would have to install a new feature from a specified source. I played around a bit with DISM and realized that the version (6.2.9200.16384) in Server 2012 has more features compared to the version (6.1.7600.16385) in Server 2008. I haven’t obviously explored them all out, but as and when I do I’ll make subsequent posts to document them.

An interesting new feature that stands out for me is the fact that the /enable-feature switch now supports an /all switch that automatically installs all the needed dependency features.

Unfortunately the /disable-feature doesn’t have a corresponding switch to remove all the automatically installed dependencies so be sure to keep track of these.

The /disable-feature does have a /remove switch though which can be used to disable a package and remove all its binaries. This is one step ahead of what the /disable-feature in the previous DISM version offers. There you could only disable the feature but the binaries (the installed files) would still be on the system; now you have an option to remove them too.

Features whose binaries are thus removed (or were never installed in the first place) are marked differently when you use /get-features:

Note the “Disabled with Payload Removed” status.

If you are trying to install a feature whose binaries (the payload) are not present /enable-features complains about that. You can use the /Source switch to specify a source for these binaries.

The /Source switch must point to a path similar to the one required by the -Source switch of the Add-WindowsFeature (see my previous blog post or this TechNet article). It must be the C:\Windows folder in a WIM file image or on a running Windows installation anywhere else on the network.

And that’s it, the feature is installed!

I think I’ll stick to DISM instead of PowerShell for a while while managing features. PowerShell has a DISM module now and hence a subset of the DISM commands, but it’s easier working with DISM exclusively for these sort of tasks as DISM has more features and eventually you will need to depend on DISM for some of these features (managing WIM images, for instance) and so I feel sticking with it exclusively will help breed more familiarity with DISM.

DISM mounted images are persistent across reboots so be sure to /unmount-wim them. You can get a list of mounted WIM images via the /get-mountedwiminfo switch.

The /discard switch is required while un-mounting to tell DISM it doesn’t need to save any changes (not that we made any changes in this case, but one could potentially make changes and save them using DISM). If you wanted to save changes instead use the /commit switch.

That’s all for now!

Installing MinShell on Windows Server 2012 Core

Inspired by this great post on improvements in Windows Server 2012 I decided to give MinShell a go.

Unlike that post, however, I was starting from Server Core and wanted to add on MinShell (not start with Server regular and remove the additional components to be left with just MinShell). Not a problem, PowerShell can be used to install the “Graphical Management Tools and Infrastructure” feature.

Hmm, bummer. That was unexpected!

In retrospect this is not surprising. It happens because (obviously) the binaries for the Server Manager GUI bits are not present in the installed system and so one must point the Add-WindowsFeature cmdlet to a source where it can get these from.

Had it been a non-GUI feature such as DNS or DHCP, the binaries would already be installed as part of Server 2012 Core – but not enabled – and so all the cmdlet needed to do would be to enable the feature. (However: if it were a non-GUI feature whose binaries were removed via the Uninstall-WindowsFeature cmdlet with the –Remove switch, then we would have had to point Add-WindowsFeature to a source if we wanted to install these features later).

The Add-WindowsFeature cmdlet has a –Source switch which lets you specify a path from where it can pick up the binaries. This must point to the c:Windows folder and that’s where the binaries are copied over from. If you have another Windows Server 2012 (non-Core) you can share its c:Windows folder and point –Source to that. Or you can mount the Windows Server 2012 (non-Core) install image from WIM file in the installation DVD and point –Source to that. If you have the WIM file from the installation DVD on a network location, you can also point to the Windows Server 2012 (non-Core) install image in that by prefixing the path with WIM: like this: –Switch wim:pathtowimfile.wim:2 (where 2 is the index of the image in this WIM file).

WIM files are sort of like containers for disk images. A single WIM file can contain many disk images – often with overlapping files – and so the size of the WIM file isn’t necessarily equal to the size of all the disk images combined. It is also a file based disk image format – meaning the images contain the actual file system and files within, not just binary data like a sector based format (such as ISO or VHD files). This is why you can actually “mount” an image from the Windows Server 2012 DVD on a folder and then browse this image as a regular file system – because it is a regular file system! The Windows installation DVDs usually contain the installation WIM file – called install.wim – in the Sources folder.

The DISM (Deployment Image Servicing and Management) command is your friend when it comes to WIM files. We met DISM earlier in the context of enabling/ disabling features and while it has a pretty straight-forward syntax it’s kind of ugly. Apart from enabling/ disabling features, you can also use DISM to inspect WIM files, mount the images within them, make changes to these images, and so on.

Before mounting an image in a WIM file, we need to inspect it to see what images are present. The /getwiminfo switch is your friend for that:

As you can see, there are four images in this WIM file. Two of these images are 7GB in size, two are nearly 12GB in size. So one would expect the WIM file containing these images to be around (7*2+12*2=)36GB in size, but in reality the WIM file is just 3.1GB. This is because all these images share the files within them and in addition to that the files are compressed. We want to install the “Graphical Management Tools and Infrastructure” feature which is present in the Windows Server 2012 Standard image (index : 2) and so that’s the image we are interested in.

To mount this image, create a folder and invoke DISM with the /mount-wim switch:

Mind you, DISM is very finicky when it comes to syntax. There is no space between the /wimfile: switch and its arguments; similarly no space between /mountdir and its arguments.

If we navigate to the c:\Offline folder we can see a regular file system with a Windows folder. Navigate through this and you’ll see its just like the Windows folder in a live Windows system. This is the folder we are interested in.

So back to Add-WindowsFeature we now pass the above mentioned folder via the -Source switch:

Success! Restart, and type servermanager in the command prompt that you get to launch MinShell!

DISM mounted images are persistent across reboots. So once you are done with it be sure to unmount the image with the /unmount-wim switch:

The /discard switch tells DISM we are not interested in it saving any of our changes to the image (not that we made any changes here; but in theory one could and save it back to the image).

Have fun with MinShell!

image.png

Adding a Server 2012 Core as domain controller to an existing domain

Added a Server 2012 Core machine as DC to my existing (virtual) domain today. Did it using PowerShell.

First up, add the AD-Domain-Services (and DNS if you plan on using that) features:

Curious about what the Active Directory related cmdlets are? This will help:

Three commands are to do with installing domain controllers:

  1. The Install-ADDSDomain cmdlet installs a new Active Directory domain configuration.
  2. The Install-ADDSForest cmdlet installs a new Active Directory forest configuration.
  3. The Install-ADDSDomainController cmdlet installs a domain controller in Active Directory.

In my case the Install-ADDSDomainController cmdlet is what’s of interest.

This cmdlet has many switches, some of the regularly used ones are:

  • -Credential to specify the credentials of the account used to install the DC. Use -Credential (Get-Credential) to be prompted for the password;
  • -DatabasePath (default: %SYSTEMROOT%NTDS) and -LogPath (default: %SYSTEMROOT%NTDS) and -SysvolPath (default: %SYSTEMROOT%SYSVOL) to specify the location where you want the database and log files and SYSVOL to be (%SYSTEMROOT is C:Windows usually);
  • -DomainName to specify the name of the domain; and
  • optionally -SiteName to specify a site name and -SafeModeAdministratorPassword to specify a safe mode administrator password (use this switch if you’d like to specify a password; if you skip you are prompted for a password anyways)

So it’s kind of straight-forward what we need to do:

Once the cmdlet completes it reboots the server, after which I manually created a DNS delegation to this domain controller for the domain (since I am installing a DNS server too).

Managing network interfaces with PowerShell v3

Update: Learnt from this StackOverflow post that the cmdlets below are only available on PowerShell v3 running on Windows 8/ Windows Server 2012 (and later). They are not available on PowerShell v3 running on Windows 7/ Windows Server 2008.

Windows Server 2012 comes with PowerShell v3 and that has the ability to manipulate the network interface from within PowerShell. Meaning you can view the IP address, set IP address, change name of the interface, and so on. I find that cool!

I explored these new cmdlets by typing Get-Net at the PowerShell prompt and pressing TAB. This shows all the commands and I kept trying the ones I felt interested in and discovered new ones from reading the help pages.

For starters, Get-NetIPInterface shows you the available network interfaces. You can pass the cmdlet parameters to filter the results in terms of (say) showing only the interfaces that are connected or showing only the interfaces that are assigned an IP from DHCP.

image.png

To see the IP addresses, use the Get-NetIPAddress cmdlet:

image.png

We can combine the two cmdlets. For instance, to find the IP addresses of the DHCP assigned interfaces one can pipe the two commands: Get-NetIPInterface –Dhcp Enabled | Get-NetIPAddress

image.png

To change an interface settings such as enable/ disable DHCP use the Set-NetIPInterface cmdlet.

To assign a new IP address use the New-NetIPAddress cmdlet (this automatically disables DHCP on that interface if it’s enabled). To change the property of an existing IP address (such as the subnet mask, for instance) use the Set-NetIPAddress cmdlet. And To un-assign an IP address use the Remove-NetIPAddress cmdlet.

image.png

image.png

I find the Set-NetIPAddress cmdlet slightly confusing. One would expect it to be able to set an IP address too, for instance, but it does not work that way. To add to the confusion this cmdlet too has switches similar to the New-NetIPAddress cmdlet to specify an IP Address (the -IPAddress switch) so you’d think it’s possible to set an IP address this way. But don’t be fooled. All this –IPAddress switch does with the Set-NetIPAddress cmdlet is to let you select interfaces matching that IP address.

If you try and set an IP address using the Set-NetIPAddress cmdlet you get an error:

image.png

The error message is obvious. You can see the cmdlet is trying to find interfaces matching the IP address you specify – and failing – rather than set that as the IP address of an interface.

Moving on, I like to rename the network adapters in my VMs. That too is possible using PowerShell now. Rename-NetAdapter is your friend!

image.png

I also like to disable some of my network adapters. You can do that too now through PowerShell using the Disable-NetAdapter cmdlet.

image.png

Would have been handy if cmdlets such as Disable-NetAdapter were a part of Set-NetAdapter (via a switch).

PowerShell is also now cool enough to fiddle with the bindings. So, for instance, if you want to disable IPv6 for one of your interfaces – possible now via PowerShell! Use Get-NetAdapterBinding to see the available bindings (IPv4, IPv6, etc) and disable using Disable-NetAdapterBinding.

image.png

Goes without saying – all these Disable-* cmdlets have an Enable-* counterpart too. So you can enable whatever you disable.

This TechNet topic gives a list of all the Network related cmdlets in PowerShell.

When assigning a new IP address to an interface using New-NetIPAddress you can pass a default gateway IP too via the –DefaultGateway switch. If you forget to do that, there’s no way to add a default gateway – perhaps using the Set-NetIPAddress cmdlet as I was expecting. The only alternatives are to remove the IP address via the Remove-NetIPAddress cmdlet and then re-add the IP address but this time specifying the default gateway; or use the New-NetRoute cmdlet to manipulate the routing table directly.

The Get-NetRoute cmdlet can be used to view the existing routing table. And the New-NetRoute can be used to add a new route. To make a route the default gateway set the destination prefix as 0.0.0.0/0 (for IPv4) or ::/0 (for IPv6). Examples below:

image.png

image.png

image.png

Lastly, there are cmdlets to configure the DNS resolvers. The Get-DnsClient cmdlet shows you DNS configuration information for each interface. It doesn’t show the resolver addresses; rather this cmdlet is about the DNS client itself and so shows information such as the DNS suffixes and the search list for these suffixes. The Get-DnsClientServerAddress cmdlet does what it says – it shows you the resolver server address for each interface – and is probably what most of us will commonly use.

image.png

To set DNS resolves you can use the Set-DnsClientServerAddress cmdlet. To specify multiple addresses put them in brackets with the entries comma separated and in double quotes. The double quotes are important because without them the addresses are ignored.

image.png

The same cmdlet can be used with a –ResetServerAddresses switch to remove the server addresses.

image.png

And that’s more or less it. These cmdlets only touch the tip of the ice-berg, but I think these are the ones most of us will regularly use.

Just to summarize here’s a table with all the cmdlets:

Get-NetIPInterface Shows you the available network interfaces. Can pass parameters to filter the results (e.g. only the DHCP assigned ones).
Get-NetIPAddress Shows you the IP addresses. Again, can filter using parameters.
Set-NetIPInterface Change an interface settings. Such as turn off/ on DHCP, IPv6 neighbor discovery settings, router settings (advertising, packet forwarding), and Wake on LAN.
New-NetIPAddress Assign a new IP address to an interface. Use the –DefaultGateway switch to specify the default gateway.
Remove-NetIPAddress Remove an assigned IP address from an interface.
Set-NetIPAddress Change IP address properties. For instance: change the subnet mask.
Rename-NetAdapter Rename a network adapter.
Disable-NetAdapter Disable a network adapter. To enable use Enable-NetAdapter.
Get-NetAdapterBinding View the network adapter bindings. Such as IPv4, IPv6, Client for Microsoft Networks.
Disable-NetAdapterBinding Disable network adapter bindings. To enable use Enable-NetAdapterBinding.
Get-NetRoute View the routing table.
New-NetRoute Add an entry to the routing table. Use destination prefix as 0.0.0.0/0 (for IPv4) or ::/0 (for IPv6) to set default gateway.
Remove-NetRoute Remove a routing table entry.
Get-DnsClient View the DNS client settings. Such as DNS suffix, search list, and so on.
Get-DnsClientServerAddress View the DNS client server addresses.
Set-DnsClient Modify the DNS client settings.
Set-DnsClientServerAddress Add DNS client server addresses. Put multiple address as (“x.x.x.x”, “x.x.x.x.”, …"). Use the -ResetServerAddresses switch to remove the server addresses

Now that’s a good reference for me too to check whenever I forget these commands!