Synology Multi-VLAN Setup

Over Christmas, my awesome wife bought me a Synology DS214 for my expanded home lab. One of the many reasons Synology was selected is because the DSM operating system supports multiple VLANs. However, the web interface only lets you set one interface. I found a number of conflicted articles describing how to configure the other VLANs. I upgraded my Synology to DSM v4.3 and then followed the process below to add the VLAN setup.

Depending on your switch setup, you may need to remove all VLAN configuration from the Synology’s port until the VLAN is created, or you can tag a single VLAN, or you can tag multiple VLANs and set a native VLAN. In a worst case scenario, you can connect the Synology to a port with no VLANs, configure the first VLAN, then move it to a properly configured tag. I trust the reader to understand and troubleshoot their local network configuration. If you do lose all connection to your Synology, you can always reset it to defaults and try again.

UPDATE: This process is confirmed to work with both DSM v4 and DSM v5!

UPDATE TWO: This will not work with DSM v6! See the comments for details.

Continue reading

PowerCLI GUI for VM Consoles

A few months ago, Dimitar Barfonchovski created a blog post on accessing the VM Console via PowerCLI, hosted on the PowerCLI Blog. Over the next few days, some cool enhancements came out focusing on a GUI for the featureset – which appear to have been lost to the great bitbucket in the sky, or I’d give some credit to them (if you know what I’m talking about, drop a link in the comments and I’ll update the article). I added a few enhancements of my own and ended up with a quick a dirty pastebin that would allow anyone to authenticate to any vCenter server and get a list of VMs they have access to.

I finally went back and combined this with last Friday’s post on creating a PowerCLI module. With a few tweaks we end up with an auto-import module and the cmdlet Get-VMConsoles. Any user can run this cmdlet. Upon connection to the specified vCenter server, you are prompted for authentication. After successfully authenticating, click Open VM Consoles and you are presented with a list of consoles available to your user. You can add a few filters, as I have done below. Ctrl-click to select the VMs you want to view and hit OK in the bottom right. Your consoles will open in your system’s browser in separate tabs.

Continue reading

vCenter Provisioning Roles

At work, one of our vSphere datacenters has a relatively static VM count maintained by a single group operating under the vCenter Administrator role. Recently, another group has joined this datacenter and will need to provision 60+ VMs, then hand over the VMs to us for ongoing maintenance and occasional provisioning of 1-2 VMs at a time. We do not want to make these users Administrators, nor do we want to provision 60+ VMs. To make this work, these new users need more rights than the VM Power User role during initial provisioning; some rights will be taken back when they move to maintenance mode. vCenter doesn’t provide any roles that match either need, so I had to create one that had all the correct permissions.

As the built-in roles do not provide the proper permissions, some trial and error was required to determine the correct combination of permissions for our situation. I do not expect that these permissions fit everyone’s needs. Please take the time to test and ensure whatever settings you do choose hit the right balance between your user’s needs and security considerations.

Continue reading

Creating a PowerCLI Module

A recent discussion on twitter about creating awesome PowerCLI output reminded me that the joy – and ease! – of creating your own PowerShell module needs to be spread.

If you do things the “right way”, by default you cannot click on a .ps1 file to open it. You need to launch PowerCLI (or launch PowerShell and import the PCLI snapins) and then import the file in whole or in part. Even if you create a new function that you want to use all the time, like a favorite “Get-SnapshotsIStupidlyLeftAroundForTooLong” function, it’s not there just by launching a PCLI/PoSH window. If you then want to modularize your PoSH into discrete parts and re-use them with other functions, you quickly end up with a very large .ps1 file that you import every time to so that all your functions are there. But they’re still functions, not cmdlets.

You don’t need to be a developer to create your own modules. Microsoft has some VERY in-depth documentation on modules that everyone should use. We’ll stick to the highlights as this is PowerShell Modules For Sysadmins. We’ll skip all the stuff about signing your code and making binary modules and focus on what most of us need every day – a way to modularize our PoSH code and streamline our ability to use it. I do encourage you to come back and look at code signing later if you plan to get serious about PoSH.

Continue reading

Migrating non-VM data between two ESXi datastores

Sometimes in the course of your work you’ll find that you need to move data between two datastores on your ESXi host or vCenter server. In my case, this occured twice, once when adding shared storage to my home lab and again when migrating some hosts from VC 5.1 to 5.5 at work. VM data is best moved via storage vMotions, but this may still leave a few files on your datastore, such as the ubiquitous ISOs folder. You could download the files from the datastore, save them on your client, and then upload them to the datastore. That’s fairly clunky, especially with the Web Client, but more importantly, it’s slow and tedious. There’s another way.

The answer is to use PowerCLI and a PSDrive. If you are not familiar with PSDrives, check out this article at the Hey, Scripting Guy! Blog for a primer. The most important command to remember is Get-PSDrive, as that will give you all the information you need to do this again in the future without having to reference this article. If you have PowerCLI installed, you will have a shortcut on your desktop for it. This will launch a window that looks like the command prompt. If you want a little more help as you drive (and you will!), I suggest using PowerShell ISE for tab completion and IntelliType. You can add the PowerCLI snapins with the following commands from the ISE:

Continue reading

Creating consistent Distributed Port Groups with PowerCLI

I recently had to create a new vDS to replicate a standard vSwitch from another vCenter install. I wanted to create my vDS Distribute Port Groups (DPG) simply, but consistently. As I have a low number of DPGs to create, I could probably have done this manually, but scripting the creation ensures consistency. Plus, it’s a subset of PowerCLI that I wanted to familiarize myself with.

First, I created a vDS and a reference DPG through the vSphere Web Client. You can do this with PowerCLI, but you have to go down the rabbit hole of Views to touch some of the advanced settings, something that’s not well documented and would have been very time consuming for me to explore. I also didn’t mind creating the initial vDS and DPG as the visual view of the Web Client made it easy for me to verify the settings whereas a long string of PowerShell (PoSH) would have been a little more difficult to interpret.

Continue reading

Adding custom resolution values to MantisBT

Recently, one of our MantisBT users asked us for a custom resolution value. The MantisBT admin guide . In the last paragraph of the suggests this is possible, but doesn’t tell you how. The closest we get is a description on implementing custom status values, plus some questionable google results that require some interpretation. I’ve done the interpretation for you, so you don’t have to. There are two existing variables in the MantisBT code that define the default status values, $g_resolution_enum_string and $s_resolution_enum_string. I’ve shortened the output to just the lines we care about:

[rnelson0@mantis ~]$ grep -R resolution_enum_string /srv/www/mantis/config_defaults_inc.php /srv/www/mantis/lang/*english*
/srv/www/mantis/config_defaults_inc.php:        $g_resolution_enum_string                       = '10:open,20:fixed,30:reopened,40:unable to duplicate,50:not fixable,60:duplicate,70:not a bug,80:suspended,90:wont fix';
/srv/www/mantis/lang/strings_english.txt:$s_resolution_enum_string = '10:open,20:fixed,30:reopened,40:unable to reproduce,50:not fixable,60:duplicate,70:no change required,80:suspended,90:won\'t fix';

You may notice a slight difference – the global var says “unable to duplicate” and the other var says “unable to reproduce”. Without any modifications, “unable to reproduce” is seen by users so we’ll take the value of $s_resolution_enum_string and use it for both.

Continue reading

Creating VMs and Templates folders with PowerCLI

As part of a migration from one vCenter to another, I wanted to recreate the same VMs and Templates look which meant recreating the folders. This is VERY slow in the vSphere Web Client and only slightly less tedious in the C# client, so I thought I’d use PowerCLI to do the trick. Here is the folder structure I wished to recreate:

Location
-Development
-Pending DeComm
-Production
  -Active Directory Domain Controllers
  -Linux Servers
  -RDP Servers
-Templates
  -Template VMs

PowerCLI has a cmdlet called New-Folder. Unfortunately, it only creates folders of the Hosts and Clusters type. To create a new VMs and Templates folder, we have to use the Get-View cmdlet. By viewing a datacenter or folder and filtering on the proper location, we can call methods to create a folder with the right context:

Continue reading

PowerCLI One-Liner – Mark all VM optical drives as Client

I’ve seen a number of articles offering PowerCLI one-liners to find all VMs with connected optical drives, or set to use a datastore, or a number of other possibilities, and mark the drives as disconnected. This is helpful, but may still cause a problem with vMotions if the optical drive is pointing to a non-shared datastore ISO. vMotion does not care if the optical drive is connected, but it does care that it’s pointing to a datastore that not all hosts can see. This one-liner will find all VMs with an ISOPath set for the optical drive and reset it to Client.

Get-VM | Get-CDDrive | Where {$_.ISOPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false

This looks for all CDDrive objects where the ISOPath value is not null and calls Set-CDDrive with the flag -NoMedia. This should take care of all the VMs where someone has set it to use an ISO on the datastore. It will NOT fix the mapping for VMs connected to the Host Device or Client Device – however, those are more rare and do not usually stand between you and a vMotion. On those rare instances, you may still need to manually dismount the optical drive on the VM or use a PowerCLI one-liner targeting those settings.

Welcome to my Blog!

Welcome, one and all!

My name is Rob Nelson, and I am starting a new blog focusing on infrastructure, virtualization, automation, and security, and the intersection of these four realms. I have been working in IT for over 15 years, starting out building white box computers after high school and currently working at a managed security services provider as a sysadmin and network, security, and infrastructure engineer. The last five years have had a strong focus on building out a VMware-based virtualization platform, automating it, and providing services to our customers securely.

I’ll be passing on lessons learned, many from the school of hard knocks, in the hopes that they help you with your job and avoid some of the pain I encountered in the learning process. I hope you’ll find the posts entertaining as well! Let me know what you think in each article’s comments, or you can find me on twitter.

Enjoy!