Index: /trunk/include/VBox/settings.h
===================================================================
--- /trunk/include/VBox/settings.h	(revision 42175)
+++ /trunk/include/VBox/settings.h	(revision 42176)
@@ -1025,4 +1025,5 @@
                && (fNameSync                  == c.fNameSync)
                && (strDescription             == c.strDescription)
+               && (llGroups                   == c.llGroups)
                && (strOsType                  == c.strOsType)
                && (strSnapshotFolder          == c.strSnapshotFolder)
@@ -1131,4 +1132,5 @@
     void readDebugging(const xml::ElementNode *pElmDbg, Debugging *pDbg);
     void readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart);
+    void readGroups(const xml::ElementNode *elmGroups, StringsList *pllGroups);
     void readSnapshot(const xml::ElementNode &elmSnapshot, Snapshot &snap);
     void convertOldOSType_pre1_5(com::Utf8Str &str);
@@ -1143,4 +1145,5 @@
     void buildDebuggingXML(xml::ElementNode *pElmParent, const Debugging *pDbg);
     void buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart);
+    void buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups);
     void buildSnapshotXML(xml::ElementNode &elmParent, const Snapshot &snap);
 
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 42175)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 42176)
@@ -24,4 +24,5 @@
 #include <VBox/com/VirtualBox.h>
 #include <VBox/com/string.h>
+#include <VBox/com/array.h>
 #endif /* !VBOX_ONLY_DOCS */
 
@@ -171,4 +172,7 @@
 
 /* VBoxManageModifyVM.cpp */
+#ifndef VBOX_ONLY_DOCS
+void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups);
+#endif
 int handleModifyVM(HandlerArg *a);
 
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 42175)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp	(revision 42176)
@@ -137,4 +137,5 @@
         RTStrmPrintf(pStrm,
                      "VBoxManage createvm         --name <name>\n"
+                     "                            [--groups <group>, ...]\n"
                      "                            [--ostype <ostype>]\n"
                      "                            [--register]\n"
@@ -148,4 +149,5 @@
                      "VBoxManage modifyvm         <uuid|name>\n"
                      "                            [--name <name>]\n"
+                     "                            [--groups <group>, ...]\n"
                      "                            [--ostype <ostype>]\n"
                      "                            [--memory <memorysize in MB>]\n"
@@ -355,4 +357,5 @@
                      "                                       keepdisknames]\n"
                      "                            [--name <name>]\n"
+                     "                            [--groups <group>, ...]\n"
                      "                            [--basefolder <basefolder>]\n"
                      "                            [--uuid <uuid>]\n"
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 42175)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp	(revision 42176)
@@ -191,8 +191,8 @@
     Bstr bstrBaseFolder;
     Bstr bstrName;
-    Bstr bstrGroups;
     Bstr bstrOsTypeId;
     Bstr bstrUuid;
     bool fRegister = false;
+    com::SafeArray<BSTR> groups;
 
     int c;
@@ -211,6 +211,5 @@
 
             case 'g':   // --groups
-                bstrGroups = ValueUnion.psz;
-                /// @todo implement group string parsing to safearray
+                parseGroups(ValueUnion.psz, &groups);
                 break;
 
@@ -242,12 +241,14 @@
     do
     {
+        Bstr bstrPrimaryGroup;
+        if (groups.size())
+            bstrPrimaryGroup = groups[0];
         Bstr bstrSettingsFile;
         CHECK_ERROR_BREAK(a->virtualBox,
                           ComposeMachineFilename(bstrName.raw(),
-                                                 NULL /* aGroup */,
+                                                 bstrPrimaryGroup.raw(),
                                                  bstrBaseFolder.raw(),
                                                  bstrSettingsFile.asOutParam()));
         ComPtr<IMachine> machine;
-        com::SafeArray<BSTR> groups; /* no groups */
         CHECK_ERROR_BREAK(a->virtualBox,
                           CreateMachine(bstrSettingsFile.raw(),
@@ -347,8 +348,8 @@
     com::SafeArray<CloneOptions_T> options;
     const char                    *pszTrgName       = NULL;
-    const char                    *pszTrgGroups     = NULL;
     const char                    *pszTrgBaseFolder = NULL;
     bool                           fRegister        = false;
     Bstr                           bstrUuid;
+    com::SafeArray<BSTR> groups;
 
     int c;
@@ -371,6 +372,5 @@
 
             case 'g':   // --groups
-                pszTrgGroups = ValueUnion.psz;
-                /// @todo implement group string parsing to safearray
+                parseGroups(ValueUnion.psz, &groups);
                 break;
 
@@ -435,8 +435,11 @@
         pszTrgName = RTStrAPrintf2("%s Clone", pszSrcName);
 
+    Bstr bstrPrimaryGroup;
+    if (groups.size())
+        bstrPrimaryGroup = groups[0];
     Bstr bstrSettingsFile;
     CHECK_ERROR_RET(a->virtualBox,
                     ComposeMachineFilename(Bstr(pszTrgName).raw(),
-                                           NULL /* aGroup */,
+                                           bstrPrimaryGroup.raw(),
                                            Bstr(pszTrgBaseFolder).raw(),
                                            bstrSettingsFile.asOutParam()),
@@ -444,5 +447,4 @@
 
     ComPtr<IMachine> trgMachine;
-    com::SafeArray<BSTR> groups; /* no groups */
     CHECK_ERROR_RET(a->virtualBox, CreateMachine(bstrSettingsFile.raw(),
                                                  Bstr(pszTrgName).raw(),
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp	(revision 42175)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp	(revision 42176)
@@ -53,4 +53,5 @@
 {
     MODIFYVM_NAME = 1000,
+    MODIFYVM_GROUPS,
     MODIFYVM_OSTYPE,
     MODIFYVM_MEMORY,
@@ -196,4 +197,5 @@
 {
     { "--name",                     MODIFYVM_NAME,                      RTGETOPT_REQ_STRING },
+    { "--groups",                   MODIFYVM_GROUPS,                    RTGETOPT_REQ_STRING },
     { "--ostype",                   MODIFYVM_OSTYPE,                    RTGETOPT_REQ_STRING },
     { "--memory",                   MODIFYVM_MEMORY,                    RTGETOPT_REQ_UINT32 },
@@ -364,4 +366,22 @@
 }
 
+void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
+{
+    while (pcszGroups)
+    {
+        char *pComma = RTStrStr(pcszGroups, ",");
+        if (pComma)
+        {
+            Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
+            pcszGroups = pComma + 1;
+        }
+        else
+        {
+            Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
+            pcszGroups = NULL;
+        }
+    }
+}
+
 int handleModifyVM(HandlerArg *a)
 {
@@ -405,4 +425,11 @@
             {
                 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
+                break;
+            }
+            case MODIFYVM_GROUPS:
+            {
+                com::SafeArray<BSTR> groups;
+                parseGroups(ValueUnion.psz, &groups);
+                CHECK_ERROR(machine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
                 break;
             }
Index: /trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 42175)
+++ /trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 42176)
@@ -491,5 +491,6 @@
       <desc>Settings version "1.13", written by VirtualBox 4.2.x.</desc>
       <!--
-          Machine changes: tracing config;
+          Machine changes: tracing config, groups, autostart;
+          NetworkAdapter changes: unit for bandwidth group limits.
       -->
     </const>
Index: /trunk/src/VBox/Main/xml/Settings.cpp
===================================================================
--- /trunk/src/VBox/Main/xml/Settings.cpp	(revision 42175)
+++ /trunk/src/VBox/Main/xml/Settings.cpp	(revision 42176)
@@ -17,4 +17,7 @@
  *
  * Certainly ConfigFileBase::ConfigFileBase() will. Change VBOX_XML_VERSION below as well.
+ * VBOX_XML_VERSION does not have to be changed if the settings for a default VM do not
+ * touch newly introduced attributes or tags. It has the benefit that older VirtualBox
+ * versions do not trigger their "newer" code path.
  *
  * Once a new settings version has been added, these are the rules for introducing a new
@@ -323,5 +326,7 @@
                 else if (ulMinor == 12)
                     m->sv = SettingsVersion_v1_12;
-                else if (ulMinor > 12)
+                else if (ulMinor == 13)
+                    m->sv = SettingsVersion_v1_13;
+                else if (ulMinor > 13)
                     m->sv = SettingsVersion_Future;
             }
@@ -3224,4 +3229,30 @@
 
 /**
+ * Called for reading the <Groups> element under <Machine>.
+ */
+void MachineConfigFile::readGroups(const xml::ElementNode *pElmGroups, StringsList *pllGroups)
+{
+    pllGroups->clear();
+    if (!pElmGroups || m->sv < SettingsVersion_v1_13)
+    {
+        pllGroups->push_back("/");
+        return;
+    }
+
+    xml::NodesLoop nlGroups(*pElmGroups);
+    const xml::ElementNode *pelmGroup;
+    while ((pelmGroup = nlGroups.forAllNodes()))
+    {
+        if (pelmGroup->nameEquals("Group"))
+        {
+            Utf8Str strGroup;
+            if (!pelmGroup->getAttributeValue("name", strGroup))
+                throw ConfigFileError(this, pelmGroup, N_("Required Group/@name attribute is missing"));
+            pllGroups->push_back(strGroup);
+        }
+    }
+}
+
+/**
  * Called initially for the <Snapshot> element under <Machine>, if present,
  * to store the snapshot's data into the given Snapshot structure (which is
@@ -3298,4 +3329,5 @@
     readDebugging(elmSnapshot.findChildElement("Debugging"), &snap.debugging);
     readAutostart(elmSnapshot.findChildElement("Autostart"), &snap.autostart);
+    // note: Groups exist only for Machine, not for Snapshot
 }
 
@@ -3450,4 +3482,6 @@
             else if (pelmMachineChild->nameEquals("Autostart"))
                 readAutostart(pelmMachineChild, &autostart);
+            else if (pelmMachineChild->nameEquals("Groups"))
+                readGroups(pelmMachineChild, &machineUserData.llGroups);
         }
 
@@ -4431,4 +4465,28 @@
 
 /**
+ * Creates a <Groups> node under elmParent and then writes out the XML
+ * keys under that. Called for the <Machine> node only.
+ *
+ * @param pElmParent    Pointer to the parent element.
+ * @param pllGroups     Pointer to the groups list.
+ */
+void MachineConfigFile::buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups)
+{
+    if (   m->sv < SettingsVersion_v1_13 || pllGroups->size() == 0
+        || (pllGroups->size() == 1 && pllGroups->front() == "/"))
+        return;
+
+    xml::ElementNode *pElmGroups = pElmParent->createChild("Groups");
+    for (StringsList::const_iterator it = pllGroups->begin();
+         it != pllGroups->end();
+         ++it)
+    {
+        const Utf8Str &group = *it;
+        xml::ElementNode *pElmGroup = pElmGroups->createChild("Group");
+        pElmGroup->setAttribute("name", group);
+    }
+}
+
+/**
  * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
  * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
@@ -4461,4 +4519,5 @@
     buildDebuggingXML(pelmSnapshot, &snap.debugging);
     buildAutostartXML(pelmSnapshot, &snap.autostart);
+    // note: Groups exist only for Machine, not for Snapshot
 
     if (snap.llChildSnapshots.size())
@@ -4610,4 +4669,5 @@
     buildDebuggingXML(&elmMachine, &debugging);
     buildAutostartXML(&elmMachine, &autostart);
+    buildGroupsXML(&elmMachine, &machineUserData.llGroups);
 }
 
@@ -4727,7 +4787,9 @@
     if (m->sv < SettingsVersion_v1_13)
     {
-        // VirtualBox 4.2 adds tracing and autostart.
+        // VirtualBox 4.2 adds tracing, autostart and groups.
         if (   !debugging.areDefaultSettings()
-            || !autostart.areDefaultSettings())
+            || !autostart.areDefaultSettings()
+            || machineUserData.llGroups.size() > 1
+            || machineUserData.llGroups.front() != "/")
             m->sv = SettingsVersion_v1_13;
     }
