Monday, December 29, 2014

The Imperfect Lab: Azure Files as a Repository

Oh, the chicken before the egg… or the horse before the cart!  I have this laundry list of things I want to do in the lab, but realized that I would likely need to store some files for my Azure VMs to access.  I will admit that the enhancements with RDP, particularly being about to copy and paste files from a local Explorer window to a remote one are super handy, but I wanted to avoid relying on connecting to the GUI as much as possible.  Plus I wanted to create a centralized location for these files, so I wouldn't need to ensure that file services was always accessible from a particular VM.

Enter Azure Files.

Azure Files allows you to create a SMB share in Azure Storage that is then accessible from machines in the same region. For the Imperfect Lab, my first goal with this is create a location where I can put some files for use later when connect to my Imperfect Lab domain controllers.  You can find a basic, step-by-step for getting Azure Files going  in the Azure documentation, but this is what I did for my lab.

Also for those of you want a neater way to copy my lines of code, you can find the code from this post here. (It's not embedded because the Blogger platform is a PITA, but I digress.)

Created a new storage account:
New-AzureStorageAccount -StorageAccountName <storageaccountname> -Location ‘West US’

Captured the Access Key as a variable:
$storageAccessKey = (Get-AzureStorageKey –StorageAccountName <storageaccountname>).Primary

You can also get the full key from the Azure Portal. Just click "Manage Access Keys" from the black tool bar at the bottom of the page for the storage account.

Created a security context with the access key:
$storageContext = New-AzureStorageContext <storageaccountname> $storageAccessKey

Created a new share:
$share = New-AzureStorageShare <sharename> -Context $storageContext

Created a directory in the share. I called mine "powershell" in this example:
New-AzureStorageDirectory -Share $share -Path powershell

I wanted to upload a file to my new directory, so I used:
Set-AzureStorageFileContent -Share $share -Source "localfilepath" -Path powershell

To check that it made it, I used: Get-AzureStorageFile -Share $share -Path powershell

Okay, now that I have my Azure Files going, I need to be able to access it from my VM in Azure.  You can do this simply by RDPing to your client, passing it your storage credentials and then mounting the share.  You'll need that key from the portal to do this since your VM likely won't be connect to your Azure subscription to capture it as a variable like I did in the previous code.

If you don't want to RDP to the machine, you can do this from the command line of your remote machine by opening a PS-Session, just note that the credentials won't be persistent that way and your mapping won't be retained after a reboot.

cmdkey /add:<storageaccount>.file.core.windows.net /user:<sharename> /pass:<accesskey>


Alternatively, if you don't have persistent credentials, you can just pass them along right with the net use command:

net use z: \\imperfectfiles.file.core.windows.net\imperfectshare /p:no /u:imperfectfiles $storageAccessKey

Once I have that drive mapped, I can use PS-Session commands remotely, yet access files that are stored locally on the VM, like CSV files or to write logs.  And if you want to delete files, use REMOVE instead of SET, or GET if you want to download them.  For example:

Remove-AzureStorageFile –Share $share –Path [foldername]/[filename]

 As an added note, Azure Files differ from Blob storage because they are accessible via SMB and allows you to build a traditional folder hierarchy if you need one.  However only VMs in the same region can access it.  Regular blob storage has the ability to be accessed globally and by the "public" without an access key.  Azure Files are accessible via both REST and SMB, where Blob storage is only accessible via REST. 

Wednesday, December 24, 2014

Some Fun Holiday Reading: Fall on the Interwebs

Here are some interesting links you might have missed that came across my Twitter feed the last few months.  I figured you might want some light reading for the holidays.  
  1. @edbott - Why Windows 10 isn’t version 6 anymore and why it will probably work. Nice explainer from @drpizza http://ars.to/1tb8eRQ 
  2. @WIRED - A definitive ranking of the most important characters in the "Hunger Games" franchise http://wrd.cm/1r6ewl7 http://t.co/XBtueePekX 
  3. @99u - What your passwords say about you: http://nyti.ms/1yYKcgD 
  4. @stevenbjohnson - Terrific backstory from @StevenLevy on the origins of “information wants to be free” (entirely news to me): https://medium.com/backchannel/the-definitive-story-of-information-wants-to-be-free-a8d95427641c?curator=MediaREDEF 
  5. @ruthm - Windows 10, OneDrive sync and the art of difficult conversations | ZDNet http://ow.ly/EyAs3 
  6. @RangerStation - How a Deaf Couple Had Their Baby Officially Registered with a Sign Name http://shar.es/1XsySc via @sharethis 
  7. @BBCNewsMagazine - This intricate pop-up medical textbook is nearly 500 years old http://bbc.in/1vliHk1 http://t.co/8aPvNzRDQX 
  8. @beckynagel - The world's biggest chocolate-maker says we're running out of chocolate http://wapo.st/1zqKCgz 
  9. @afreshspace - Digital tools for remote workers...some of my faves on here! http://buff.ly/1EK3s5f 
  10. @MichaelBender - Amazing video on creative experience on #SurfacePro3 with #adobe. https://www.youtube.com/watch?v=PlLR9ANGsOo 
  11. @HeikeRitter - Freaking awesome! Mobile Azure Manager for Windows Phone is NOW available! Manage your #Azure stuff "on the go" http://ow.ly/DKxBq 
  12. @windowsserver - Want to understand Active Directory Federation Services at a deeper level? Then this blog post is for you! #MSPFE http://cic.ms/bSmQnH 
  13. @bbnetman - Number 1 Reason to Upgrade to PowerShell 4.0: Desired State Configuration - Hey, Scripting Guy! Blog http://blogs.technet.com/b/heyscriptingguy/archive/2014/10/24/number-1-reason-to-upgrade-to-powershell-4-0-desired-state-configuration.aspx?linkId=10187347 
  14.  @2600 - A fairly decent BBC piece on the hacker world http://www.bbc.com/news/technology-28214646



Monday, December 22, 2014

Yeah! Windows Phone!

This morning, I woke up to an early Christmas present.... Verizon was finally updating my Lumia 922 with Windows Phone 8.1.  I've only been waiting for this for what seems like forever.

There were actually two updates that needed to be done, but I think the first one was related to the fact that I had recently factory reset my phone to fix a few other odd problems it had been having. Not totally sure, but who cares, right?  It's on 8.1!!

Go Verizon!!!  (Sort of, but not really...)

Friday, December 19, 2014

The Imperfect Lab: Creating Client Machines

Playing with domain controllers is all well and good, but I also needed some client machines in my lab.  My goal for the exercise was to be able to create a couple new VMs in the proper subnet and have them automatically join to my domain.

I debated making having each VM in its own cloud service or sharing one cloud services for all my client VMs.  I went with the latter just to keep things neater.  I don't think there is a right or wrong pick on that one - my client VMs will simply all share the same external *.cloudapp.net DNS name.

For networking, the recommended guidance is to not mix machines with static/reserved DHCP addresses (like my DCs) with machines that are going to use the standard DHCP.  Thus my client machines will go into the alternate subnet I have in my ImperfectNet.

  • ImperfectNet
    • FirstSubnet (192.168.1.0/24)
    • HalfSubnet (192.168.2.0/25) <- right in here!
    • Gateway (192.168.3.200/29)

Since I would be creating a new cloud service name, there are few requirements to keep in mind.  Cloud service names need to meet DNS standards, so they have to start with a letter, end with a letter or number, can only include letters, numbers and hyphens and must be between 3-15 characters.

Because they must also be unique to the "cloudapp.net" domain, you might want to check that your name is available before incorporating it into your script.

Test-Azurename -service "CloudServiceName"

The results of this command will be either "True" or "False".  You might think this means:
  • True = name already used
  • False = name not used, thus available

 But this thinking will lead you astray.  A "TRUE" response can mean that the name is already in use, but it can also mean that it did not meet the DNS standards.  The line below will return "TRUE" because its longer than 15 characters and includes an underscore.

Test-Azurename -service "imperfectlab_clientmachine1"

Anyway, once you've got a good cloud service name sorted out, you'll want to deploy a VM or two into it.  For my lab, I went with two VMs one running Windows 8 and one with the Windows 10 TP.  (If you are playing along at home don't have an MSDN subscription that gives you the option to use the Clients OS choices from the gallery, feel free to use another copy of server.)

I set up all my necessary variables, including two different ones for the OS images.  You may want to have different usernames and passwords for the domain vs. the local admin on the clients, but for my ease of not forgetting things in the lab, I've been making all mine the same for now.

$image = "03f55de797f546a1b29d1b8d66be687a__Windows-8.1-Enterprise-x64-en.us-201410.01"
$image10 = "03f55de797f546a1b29d1b8d66be687a__Windows-10-Technical-Preivew-Enterprise-x64-en.us-201411.01"
$pwd = "password"
$un = "username"
$subnet = "halfsubnet"
$instancesize = "Small"
$domainjoin = "imperfectlab.com" #this is the domain FQDN
$domain = "imperfectlab" #this is the domain name
$VnetName = "imperfectnet"

Because the variable are preset, I can reuse the same line of code almost exactly, with only a couple of tweaks.

$newVM1 = New-AzureVMConfig -Name "Imperfect-Win8" -InstanceSize $instanceSize -ImageName $image |
    Add-AzureProvisioningConfig -WindowsDomain -JoinDomain $domainjoin -Domain $domain -DomainPassword $pwd -Password $pwd -AdminUsername $un -DomainUserName $un | 
    Set-AzureSubnet -SubnetNames $subnet 

$newVM2 = New-AzureVMConfig -Name "Imperfect-Win10" -InstanceSize $instanceSize -ImageName $image10 |
    Add-AzureProvisioningConfig -WindowsDomain -JoinDomain $domainjoin -Domain $domain -DomainPassword $pwd -Password $pwd -AdminUsername $un -DomainUserName $un | 
    Set-AzureSubnet -SubnetNames $subnet

New-AzureVM -ServiceName "ImperfectClients" -VMs $newVM1 -Location "West US" -VNetName $vnetName
New-AzureVM -ServiceName "ImperfectClients" -VMs $newVM2

For the 2nd VM, I didn't need to include the "Location" and "VNetName" switches because the cloud service would have already existed due to the creation of the first VM. 

The beauty of this was once I had worked out what I wanted, I kicked off the script and walked out to get coffee.  When I came back, everything was up, running and domain joined.  Look Ma! No portal needed!

Tuesday, December 16, 2014

The Imperfect Lab: A Few VM Manageability Tweaks

Today in the Imperfect Lab I'm going to work on some clean up to improve the manageability of my new domain controllers. Since I have two of them, I want to take advantage of the Azure's service level agreement.  The only way to ensure that Azure keeps at least one DC running at all times is to create an availability set, which will distribute the VMs within a set across different update and fault domains.

Some notes about Availability Sets - VMs must be in the same cloud service and you can have a maximum of 50 in each set. You will find that your machines are spread across 2 fault domains and upwards of 5 update domains.  Also, avoid creating a set with just one machine it, because once you create a set you won't get notifications about maintenance regarding those update/fault areas. 

Since my machines have already been created I use the following PowerShell to update them with a set named "ADDC".

Get-AzureVM -ServiceName "imperfectcore" -Name "dc-cloud1" |
    Set-AzureAvailabilitySet -AvailabilitySetName "ADDC" |
    Update-AzureVM

Get-AzureVM -ServiceName "imperfectcore" -Name "dc-cloud3" |
    Set-AzureAvailabilitySet -AvailabilitySetName "ADDC" |
    Update-AzureVM

If you want a quick gander at all the availability sets that exist in your subscription, run this:

(Get-AzureService).servicename | foreach {Get-AzureVM -ServiceName $_ } | select name,AvailabilitySetName

Since the GUI does hold a fond place in my heart, I do want the dashboard of Server Manager on one of the VMs to show the status of all the servers in the domain.  You'll notice that if you log into the desktop of one of these newly created servers the "Remote Management" will be disabled.  This needs to be enabled to allow management from other services, so run "winrm quickconfig -q" against each server to turn that on.  You will have to start a PS-Session for each server for that.

Finally, since I expect to reduce the amount of times I'm logging into a machine directly, I'm going to take switch one of the DCs to Server Core and the other to the MinShell format.  These commands do take a while to complete and require a restart to complete the configuration, so don't panic if you can't connect to what looks like "running" VMs in Azure for a few minutes after reboot.

For Server Core (from a Machine running the Full GUI):
Remove-WindowsFeature -name User-Interfaces-Infra
Restart-Computer -Force

For MinShell (from a Machine running the Full GUI):
Remove-WindowsFeature -name Server-GUI-Shell
Restart-Computer -Force

With the MinShell installation I will still have access to the nice Server Manager dashboard when I want it and will be able to remotely manage the 2nd domain controller from it.  The list below will show the differences between each of the versions. (Click to make it bigger!)




Thursday, December 11, 2014

The Imperfect Lab: More DCs and Static IPs

When I was last working in my Imperfect Lab, I added another server to the existing cloud service and decided to make it a domain controller.  When you set up domain controllers (cloud or on-premises) a few things become really important - IP Addresses and DNS.

By default, Azure will provide DNS services from the fabric if you don't specify your own DNS.  You would think there is some PowerShell to do that directly, but surprisingly there isn't.  You can set the DNS for each network using the Management Portal or by exporting the network configuration file and updating it.  I just used the portal and made sure that my ImperfectNet listed the IP address for both servers that would act as domain controllers.

If you don't set a domain controller as the DNS server, all the VMs that come up inside your virtual network will look to an Azure fabric DNS server and won't be able to authenticate to your domain.  Since this is a crucial to AD function, I also wanted to make sure that the VMs that were acting as domain controllers had static internal IP addresses. 

Now, these addresses aren't really "static" on the OS. They are more like DHCP reservations handed out from the fabric manager.  But the end result is the same - VMs that have the correct IP address, regardless of the order they are started.

To do this with PowerShell, you first need to have the VMs in the Stopped (Deallocated) state. This way the addresses are free to assign.  If the VM is already running, the address is allocated already, thus can't be assigned.  You can double check that an address is free with:

Test-AzureStaticVNetIP –VNetName ImperfectNet –IPAddress 192.168.1.5

To set the static address, I used:

Get-AzureVM -ServiceName ImperfectCore -Name DC-Cloud1 | Set-AzureStaticVNetIP -IPAddress "192.168.1.4" | Update-AzureVM

Take note of the use of quotes around the IP address in that last line. It matters. I don't know why.  Just trust that I wasted a lot of time on your behalf for that knowledge.

Then to finally kick off the addition of my second domain controller in this domain, I used:

Install-ADDSDomainController -Credential (Get-Credential) -DatabasePath 'C:\Windows\NTDS' -DomainName 'imperfectlab.com' -InstallDns:$true -LogPath 'C:\Windows\NTDS' -NoGlobalCatalog:$false -SiteName 'ImperfectNet' -SysvolPath 'C:\Windows\SYSVOL' -NoRebootOnCompletion:$true -Force:$true -Verbose

One note about the paths used for the logs and SYSVOL… I've left them on C:\ for convenience, but for production, you will want to set up your DCs in Azure with an additional disk where you direct those files to go.  Read more about the reason behind that best practice here.

Also, if this Domain Controller happens to connect back to an on-premises domain. Be sure to make the proper changes to you AD Sites and Services to ensure proper site topology.

Update (12/26/14): For easy access to code snippets, you can find them here.

Tuesday, December 9, 2014

The Imperfect Lab: There's No Such Thing as a Free Gateway

Sometimes I forget that the internet isn't really free.  I have the convenience of having a MDSN subscription from work, so I enjoy the access to a set amount of Azure credits each month to spend.  However, some things are more "spendy" than others and gateways fall into that category for me, particularly for a testing scenario that doesn't have a "real" business need behind it.

MSDN users of Azure do get some discounted rates. All instances for Windows and Windows Server Virtual Machines, Cloud Services, Websites, and HDInsight are discounted up to 40% off our Pay-as-you-go rates. The MSDN rate on these services is equal to the rate for a Linux virtual machine of the same size and type. (For more details about MSDN benefits visit http://azure.microsoft.com/en-us/pricing/member-offers/msdn-benefits-details/)

But all the other things are billed at regular rate, for gateways that rate is about $.05 per hour, a tad over one dollar a day.  When connecting a VNET to a VNET you are paying for two gateways, so my costs just to keep that running for my Imperfect Lab will eat up about a third of my monthly credits.  Take note, even gateways you aren't actively using are charged. So if you have a point-to-site gateway setup for clients to connect with but no clients are connecting, that's being charged too, just to keep it available. 

So with the holidays coming and my growing list of things I'd like to do in the lab, I'm going to rip down the VNET-to-VNET connectivity for the time being.  I'm going to build out my little infrastructure in one VNET to start and then extend it to the second VNET once I really have a set plan in place.

Onward to my domain controller creation and tying that into Azure Active Directory. Stay tuned.

Monday, December 1, 2014

The Imperfect Lab: Deploying More VMs

As I mentioned, I had created my first VM in my Imperfect Lab with the Azure Portal.  But I wanted to be able to do this using PowerShell from my workstation To recap my "physical" set up so far:
  • VNETs
    • ImperfectNet
    • AnotherNet
  • Storage Accounts in Different Regions
    • imperfectstore (West US)
    • anotherstore (East US)
  • Cloud Services
    • imperfectcore
    • anothercore
(I don't think I've mentioned it before, but if you are just starting out and need to get your ISE connected to you Azure account, just run Add-AzureAccount. You'll get prompted for your credentials.)


To start, I'm just going to create an additional server in the same network as my current domain controller.  Then I'll have a server I can promote to DC later, or use for another service. 

If you have multiple subscriptions and/or multiple storage accounts set up, like I do, you need to make sure Azure knows where you want to put things. My subscription happens to be the Visual Studio one.

Set-AzureSubscription -SubscriptionName "Visual Studio Ultimate with MSDN" -CurrentStorageAccount "imperfectstore"

Then you'll want to configure the basic variables for your VM. In this case, this is the adminstrator name and password, as well as the name of the Windows Server 2012 R2 image available at the time of this exercise. You'll want to make sure to get the current name of whatever OS you want to install.

$un = "adminname"
$pwd = "secretpassword"
$image = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201411.01-en.us-127GB.vhd"

Pick up that VM image the full list with: Get-AzureVMImage | Select ImageName

Then,  configure a few more variables using the New-AzureVMConfig.  In this case, I'm settting the server name and instance size, pulling in the username and password variable I set with the lines above and specifying the pre-existing subnet I want to use.

$newVM = New-AzureVMConfig -Name "Server2" -InstanceSize "Small" -Image $image |
     Add-AzureProvisioningConfig -Windows -AdminUserName $un -Password $pwd |
     Set-AzureSubnet -SubnetNames "FirstSubnet"

Finally, kick off the VM creation with one of the following options: 
  • Into an Existing Cloud Service: New-AzureVM -VMs $newVM -ServiceName "imperfectcore" 
  • Into an New Cloud Service:  New-AzureVM -VMs $newVM -ServiceName "newcloudservice" -Location "West US" -VNetName "imperfectnet" 
Give this all a few minutes to cook and your new VM will be deployed. I haven't joined it to the domain yet... baby steps here, baby steps!  I like to make sure one thing works at time, so it's easier to troubleshoot when I have issues.  That's what a lab is for, right?  

Update (12/26/14): For easy access to these code snippets, you can find them here.



MS ITPro Evangelists Blogs

More Great Blogs