Showing posts with label imperfect lab. Show all posts
Showing posts with label imperfect lab. Show all posts

Tuesday, February 10, 2015

The Imperfect Lab: Check out the Microsoft Test Lab Guides

If you've been reading along for a while now, you know I've been having a blast building and expanding my Imperfect Lab. But I admit, if you are looking for a full step-by-step guide to what to actually put in you lab, I've haven't given you all that.  But I do know somewhere you can look!

Available right inside the official Azure documentation is the details (including PowerShell) for setting up a hybrid cloud environment for testing.  Now, this first guide requires you to have a physical data center lab to connect to using RRAS, but you can easily rework it for a VNET-to-VNET if that's what you desire, by following these instructions instead.

Once you have the basics in place, you can do things like build a full SharePoint Farm (on my short list), set up a Web-based LOB application or set up DirSync. Or do all of them!


Tuesday, January 27, 2015

The Imperfect Lab: Letting Additional Administrators Remotely Connect to Servers

An age-old server administration best practice is to make sure that everyone who is administering servers on your network are doing it with their own "admin" credentials.

Up until this point, I've done all my remote Azure sessions (PS-Session) with the built-in administrator account.  This works fine if you are only person connecting remotely to a server. But what if you want to grant others administrative rights to your machine and they would also like to connect remotely?

Your first step would likely be to add them to the local administrators group. Since you've already turned on the "remote management" feature for yourself, you might expect this to work out of the box.

But you probably overlooked this little note in the "Configure Remote Management" box when you enabled remote management - "Local Administrator accounts other than the built-in admin may not have rights to manage this computer remotely, even if remote management is enabled."

That would be your hint that some other force might be at work here.  Turns out that UAC is configured to filter out everyone except the built-in administrator for remote tasks.

A review of this TechNet information gives a little more detail:

"Local administrator accounts other than the built-in Administrator account may not have rights to manage a server remotely, even if remote management is enabled. The Remote User Account Control (UAC) LocalAccountTokenFilterPolicy registry setting must be configured to allow local accounts of the Administrators group other than the built-in administrator account to remotely manage the server."

To open up UAC to include everyone in your local Admins group for remote access, you'll need to make some registry changes.

Follow these steps to manually edit the registry:

  1. Click Start, type regedit in the Start Search box, and then click regedit.exe in the Programs list.
  2. Locate and then click the following registry subkey:
  3. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system
  4. On the Edit menu, point to New, and then click DWORD Value.
  5. Type LocalAccountTokenFilterPolicy for the name of the DWORD, and then press ENTER.
  6. Right-click LocalAccountTokenFilterPolicy, and then click Modify.
  7. In the Value data box, type 1, and then click OK.
  8. Exit Registry Editor.

Now you will be able to remotely connect and administer your server using PowerShell with any account you've give Admin rights too for that particular server.  This would hold true for servers in Azure, as well as servers on your local network.

Special shout out to Bret Stateham for bringing this "remote admin road-bump" to my attention. Sometimes what looks like an "Azure" problem, is really a "Server" feature. :-)

Tuesday, January 20, 2015

The Imperfect Lab: Not So SharePointed

On my list of thing to try with the Imperfect Lab was deploying a SharePoint Farm from the new portal since there is this nifty wizard that just does all the work of building the servers for you.  Just a few clicks and boom, SharePoint!

But alas, it was not quite to be. While the portal does do what it claims, produces a test/dev scenario of SharePoint, it's completely isolated.  And completely isolated isn't exactly what I wanted. When you use the portal configuration "wizard" you are prompted for several bits of information that you can't get around.
  1. You are prompted to give a domain name for a new FOREST domain.
  2. You must create a NEW virtual network.

Because I wanted to create a little Imperfect Lab "team site" and experiment a bit with SharePoint 2013, I wanted to use my existing domain and my existing network.  But that isn't an option allowed via the portal "journey", to get what I want, I'll have to build it out the old-fashioned way, one server at a time.

Had I know this before I started this project, I might have considered creating the SharePoint farm first, then using that domain and network as the basis for the rest of my lab projects.  Oh well, that’s why we experiment in the first place right?  Live and learn. I guess I'll swing back around to this SharePoint project a bit later.

Meanwhile, if a completely isolated SharePoint playground is something you need, by all means check out the new Azure portal and give it go.  And if you need more than what the test environment provides, you might find the complete Planning for SharePoint 2013 on Azure Infrastructure Services guide useful.

Wednesday, January 14, 2015

The Imperfect Lab: Syncing AD to Azure AD

Today I decided to ease myself into my next steps and build out a member server to sync AD to.  I reused some previous PowerShell to deploy a member server and join it to my domain.  It is possible to run the sync services on an existing domain controller, but as a best practice I don't like to install one-off applications on my domain controllers.  I like to keep them identical, thus the need for different member server to perform the sync role.

I had previously uploaded the Microsoft Azure AD Sync Services (aka AADSync) application to my Azure file share, but you can find it at http://aka.ms/azureadsync.  You will want to install and run the Microsoft Azure AD Connection Tool.  Please note that Microsoft Azure AD Sync Services is DIFFERENT from Windows Azure Active Directory Sync (aka DirSync)

Once the Sync Server is built, you will want to kick off the installation of the application, but not before you'd made some adjustments to your Azure Directory.  In the Portal, I went to my directory and created a new user account to be my Azure AD Administrator (newuser@imperfectlab.com) and made it a Global Administrator.  You will also need to go through the sign-in process to set a non-temporary password.

Once you have this account, you simply need to throw the switch under "Directory Integration -> Directory Sync" from Inactive to Active.  Once the setting is saved, the "Last Sync" field will say "never synced".  Now go over to your sync server and run that connection tool.

You'll need the account and credentials you created for the new Azure AD Admin and some information about your domain.  For the addition of the forest, you'll need your domain name and the username and password of a enterprise domain admin from your local domain.  This will be different than the account your created directly in Azure AD.

Leave the User Matching page at the defaults but select "Password Synchronization" from the Optional Features. Finally, review your configuration screen and verify that "Synchronize Now" is checked and click finish.  At this point, your users should sync into Azure AD and after a few minutes you'll see a list of them in the portal.

If you want to make any changes to the settings of your AD Sync, like adding in a feature, simply rerun the tool after disabling the Azure AD Sync Task in Task Scheduler.  The task will be re-enabled automatically when you finish the wizard again.

If you want to force a sync for Azure AD Sync Services for any reason, the default location of the command line tool is:
c:\program files\microsoft azure ad sync\bin\directorysyncclientcmd [initial|delta]


Happy Syncing!

Wednesday, January 7, 2015

The Imperfect Lab: Adding A Custom Domain

This will be a super short post, because this task is super easy!

My lab in Azure wouldn't be complete without its own custom domain. Honestly, this is one of those "just pop over to the Portal" tasks because it only takes a few clicks, particularly if you are only doing it once.  But you won't be able to complete in a hurry, because your registrar will update the public DNS entries on their own sweet time and that update is needed to complete the process.

By the way, if you really want to do this without the Portal, you can find information on installing the right PowerShell modules and the commands here. (http://msdn.microsoft.com/en-us/library/azure/jj151815.aspx)  If you are going to managing multiple tenants over time, PowerShell will likely be the best way to go.

Anyway, when you are in the Portal, click "Active Directory" in the navigation.  Select the domain directory you want to add a custom domain to.  In this case, I wanted to create a new Azure Directory for the Imperfect Lab, so I clicked "New" and then went to APP SERVICES -> ACTIVE DIRECTORY -> DIRECTORY -> CUSTOM CREATE.

I named my directory "ImperfectLab" and picked my region.  The domain name for the directory is now "Imperfectlab.onmicrosoft.com".  Since I don't want to be using the "onmicrosoft.com" moniker for very long, I need to add my recently purchased domain.  You actually have to a own (or at least control) the domain you want to add because it's requirement to add a TXT or MX record to your public DNS.

Click into the directory you want to use and go to the "Domains" section. On the bottom action bar, click "Add". Then type in the FQDN for your "real" domain, in my case "imperfectlab.com".  You be given the information to create either at TXT or MX record that needs to be added to your DNS records managed by your registrar.

My registrar doesn't accept the @ symbol for the parent zone, but leaving that field blank worked fine.  You have to add the record, wait for the external DNS to update and then return to the portal to verify it.

Once verified, you can create (or sync) users into your Azure Active Directory using either your "user@domain.onmicrosoft.com" UPN or your "user@domain.com" UPN.

Monday, January 5, 2015

The Imperfect Lab: Fleshing Out Active Directory

Having a domain with no users isn't any fun.  So my next task for the Imperfect Lab was to create a few accounts to act as my users for provisioning access and eventually syncing with Azure Active Directory.

You can do a lot with some basic PowerShell to create OUs and User Accounts.  Here are a few basic lines that would create something in my lab domain:

New-ADOrganizationalUnit –Name “DOGS” –Path “DC=imperfectlab, DC=Com”

New-ADUser -Name "Lizbeth Tiburon" -Path "OU=DOGS,dc=imperfectlab,dc=com" -AccountPassword $newPassword -Department "Career Changed" -SamAccountName "LTibu" -Surname "Tiburon" -GivenName "Lizbeth" -DisplayName "Lizbeth Tiburon"

Those lines would create a OU and then a user account in the new OU.  But what if you wanted to create more users at once?  I could simply duplicate the 2nd line, but figured there had to a relatively easy way to get data straight from a CSV file.

I did some looking around online and since no good Internet search goes unpunished, I found this: https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Create-Active-7e6a3978#content by @mwashamtx.  Honestly, this a great script that I couldn't have written by myself at this point, but I was able to tweak it enough to do my bidding. 

I changed the paths (to reflect the drive letter and file location I set up using Azure Files), removed a lot of the fields the script used to populate account attributes and edited the CSV file to match.  I uploaded my CSV file to my Azure file share. I left the script writer's five character SAM account name creation as is and ran it remotely via PS-Session on my domain controller.  The DC tapped the CSV file in my Azure File share and wrote the log to that same location.  The script does some great error handling, which was really helpful for troubleshooting.  Mission accomplished!

And for those of you who are curious about the user created in that line above, Lizbeth is a dog who didn't complete the training to become a guide dog

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. 

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.



Wednesday, November 26, 2014

The Imperfect Lab: Standing Up Active Directory in Azure with PowerShell Remoting

Today in my Imperfect Lab, I needed to start adding some servers so I could build out a domain. So I popped over to the management portal and quickly spun up "DC-Cloud1" in the "FirstSubnet" of my ImperfectNet.

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

I logged in and was just about to click "Add Roles/Features" when I paused. What fun is that? I've installed AD a million times that way and it would be way more interesting to do it from PowerShell ISE from my laptop. So I closed out my RDP session and got to work.

First you have to install the remote access certificate on your local machine. To do that you want to download this script - Configures Secure Remote PowerShell Access to Windows Azure Virtual Machines.  Put is somewhere easy to access, open it in PowerShell ISE and then feed the script your personal variables to install the certificate on your machine.  Once that's done, you'll be able to use the lines below to open a PowerShell session directly to your VM. (For more info Michael Washam's script, check out his post, Introduction to Remote PowerShell with Windows Azure.)

$uri = Get-AzureWinRMUri -ServiceName $cloudServiceName -Name $Name 
$cred = Get-Credential  
Enter-PSSession -ConnectionUri $uri -Credential $cred  

Now that I had a secure, remote session it was time to install Active Directory.

Add-WindowsFeature -name ad-domain-services -IncludeManagementTools
Install-ADDSForest -DomainName "yourdomain.com" -ForestMode 5 -DomainMode 5

Those "mode" numbers are adjustable for controlling the forest and domain functional levels. 5 is for 2012. For Server 2003 functional level use 2, for Server 2008 use 3.

Finally, just in case I wanted easy access to RDP to the machine, I installed the newest Remote Desktop Connection Manager 2.7. This way I don't have to download and keep track of RDP files from the Azure Portal every time. (Shout out to Tommy Patterson for letting me know about that version update last week!)

Tuesday, November 25, 2014

The Imperfect Lab: Connecting a VNET to another VNET

As I mentioned yesterday, I'm struggling with setting up the "perfect" lab environment for myself. So instead of trying to make it perfect, I'm just going to start by simply getting started and letting in evolve.  Because starting is most of the battle, right?  Most environments grow and change and become a bit messy, so I am just going to embrace a little chaos!

My starting goal is to create two networks in Azure (in two different regions) and connect them.  To start I'll need two VNETs in Azure. I also created two corresponding storage accounts in each region, so that when I'm building my servers, everything is as neat an organized as I can make it.

In each of the networks, I carved out a few subnets, because I don't know exactly what I'm doing with them yet. Keep in mind you will need to make at a small Gateway subnet in each. Also, as soon as you put a VM in a subnet, you can no longer edit it.

  • ImperfectNet - 192.168.1.0/22 (West region)
  • AnotherNet - 192.168.4.0/23 (East region)
Because I want to connect them together with site-to-site networking, I have to create corresponding "local" networks in Azure to sort of trick each network into thinking its connecting to a physical network.  So under the "Local Networks" tab, I created "ImperfectLocal" and "AnotherLocal" with the same IP address ranges as the virtual networks. Be sure to put in a fake VPN Gateway Address as a placeholder here, you'll update it later after Azure gives you a real gateway address.

In each network, I threw the ticky-box under Site-to-Site Connectivity, selected the correct "local" network and then created the Gateway subnet.  After everything was finished configuring, when you return to the dashboard page of each network, you will see the remote network showing.  Azure will tell you that "the gateway was not created".

Click "create gateway" at the bottom. For VNET to VNET connectivity, you have to go with Dynamic Routing.  Do this for each network and wait for it to complete.  (Creating gateways actually takes a while, this might be a good time to get lunch.)

Once your gateways are created, write down the IP addresses carefully and then edit those "local networks" with the fake VPN gateways to the correct ones Azure just assigned you.

Finally, you have connect the networks together with shared key.  There isn't any way to do this in the portal, so pop over to PowerShell and use the following code to hook them together.  You have to run the command twice with the corresponding network names and the SAME shared key. Please make your key longer then the sample I put in here.

Set-AzureVNetGatewayKey -VNetName YourVNETName -LocalNetworkSiteName TheOppositeLocalNet -SharedKey abc123xyz

Set-AzureVNetGatewayKey -TheOtherVNetName YourVNETName -LocalNetworkSiteName TheOtherLocalNet -SharedKey abc123xyz

So now I've got two connected networks in Azure, albeit empty of servers.  Next up... starting to build out my "imperfect" domain.

One more thing... if you want the offical "Azure" instructions for this, complete with images, go to http://msdn.microsoft.com/en-us/library/azure/dn690122.aspx.  







Monday, November 24, 2014

The Quest for the Perfect Lab

There are a few old sysadmin jokes out there... one that often comes to mind for me these days is the one-liner about how the perfect network is one that no one is on.  But now that I have the luxury of being able to build just about any lab network I want (either in Azure or using Hyper-V) I find myself nearly paralyzed by wanting to build the "perfect" network/lab for my needs.

I start, I stop, I get sidetracked by a different project, I come back to my plan, only to realize I've forgotten where I left off (or forgotten where I wrote down that fancy admin password for that VM) and end up tearing it out and starting over again.  The end result is I'm getting no where fast.

I've got several MCSE exams in my future that I need to build some things for hands on for.  I have a little internal metric of how I need to improve my PowerShell a bit more.  I have work training items that sort of fit into all this and I keep striving for the perfect lab, the perfect naming system, the perfect password that I won't forget... well, I guess my "perfectionist" is showing.

It's a slow week here in the office with the Thanksgiving holiday approaching, so now is the perfect time to sit down with a pen and a paper and really figure out what I'm going to build and what I want to use it for.

Because there is something worse than a network that no one uses.  It's that network I keep deleting.

MS ITPro Evangelists Blogs

More Great Blogs