# Business Unit support

> How business unit support works in the scripting library, including prefixing a group name to create it in the device's own business unit.

Source: https://docs.capaone.com/capainstaller/vb-scripting-library/addendum/business-unit-support/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Using Scripting Library to Manipulate Group Membership within Business Units

The CapaInstaller Scripting Library has some useful functions for manipulating the group memberships of units within the CapaInstaller environment. System administrators can create groups in Business Units with names that match existing groups at the point level. This is legal but poses a problem for manipulating unit membership of groups with similar names because, currently, there is no way for the CapaInstaller environment to distinguish between groups at the point level and groups at the Business Unit level. The current implementation of Scripting Library does not allow adding new parameters to existing functions without severe consequences to existing code, so instead of adding a new parameter, we chose to expand the use of the sGroup parameter to describe the location of groups in Business Units explicitly.

When you want to manipulate group members in a Business Unit, you simply prefix the sGroup parameter with the constant **BU_GROUP_PREFIX**. When you do this, the CapaInstaller environment will know that the group you refer to must exist within a Business Unit. If you try to add a unit to a group that does not currently exist, that group will automatically be created. If you do not prefix sGroup with **BU_GROUP_PREFIX**, the CapaInstaller environment will manipulate group membership at the point level. When listing the group membership of a unit all groups that exist in a Business Unit will have **BU_GROUP_PREFIX** prefixed in their names.

### **NOTE: These variables are managed by CapaInstaller Windows Agent. If an agent is not running, the values will typically not represent the current state.**

### Example

**VBScript**

```vb
If bStatus Then bStatus = CMS_AddComputerToStaticGroup(gsUnitName, "Group Name")
If bStatus Then bStatus = CMS_AddComputerToStaticGroup(gsUnitName, BU_GROUP_PREFIX & "Group Name")
```

This will add a unit to 'Group Name' at the point level and add it to 'Group Name' inside its Business Unit. The selected Business Unit is dynamic and will be selected based on the gsUnitName parameter. If gsUnitName is not linked to a Business Unit, nothing will happen.

### Example

**VBScript**

```vb
If bStatus Then bStatus = CMS_GetGroupMembership()
For index = LBound(gaValue) to UBound(gaValue)
  xStatus = Job_WriteLog("Install", "Index #" & index & ": '" & CStr(gaValue(index)) & "'", bStatus, True)
  If CStr(gaValue(index)) = BU_GROUP_PREFIX & "Group Name" Then
    xStatus = Job_WriteLog("Install", "'Unit is member of: '" & CStr(gaValue(index)) & "'", bStatus, True)
  End If
Next
```

If a unit is a member of a group inside a Business Unit, its group name will have the **BU_GROUP_PREFIX** prefix. If you need to make string comparisons, you must prefix the group name with the **BU_GROUP_PREFIX** constant.

Two other variables can be useful in a script:

**gbIsMemberOfBusinessUnit** can be used to determine if the current unit is linked to a Business Unit.

**gsBusinessUnitName** can be used to get the name of the Business Unit that a unit is linked to. If the unit is not linked to a Business Unit, this variable will be an empty string.

### Example

**VBScript**

```vb
If bStatus And gbIsMemberOfBusinessUnit Then
  If bStatus Then bStatus = CMS_AddComputerToStaticGroup(gsUnitName, BU_GROUP_PREFIX & "Group Name")
End If

If bStatus And gsBusinessUnitName = "Business Unit Name" Then
  If bStatus Then bStatus = CMS_AddComputerToStaticGroup(gsUnitName, BU_GROUP_PREFIX & "Group Name")
End If
```

You can use these variables to make decisions based on membership and names of Business Units.

### PowerShell (PowerPacks)

Use **BU\\** in front of the group name to create a group in the BU that the device is a member of.

### Example

**PowerShell**

```powershell
if (CMS_AddComputerToStaticGroup -group 'BU\\static1') {
  $cs.Job_WriteLog("Added", "Computer added to static group: 'static1'")
}
```
