Help Center
Choose product document...
Veeam ONE 9.5
Business View User Guide

Synchronizing Data with a Sample Script

This section describes how to synchronize categorization data for VMware vSphere using a sample Microsoft PowerShell script. The script creates a CSV file based on Active Directory data. To follow this example, make sure Microsoft PowerShell installed on the Veeam ONE Server.

Step 1. Create a Script

Create a script file named AD2CSV.ps1 which uses Active Directory infrastructure data to create a CSV file with a categorization model.

A sample script is provided below:

#define maps. Map groups and categories to specific folder in AD
#("category", "group", "folder in AD", "path to folder in AD")
$maps=
("Location_", "UK_", "Computers UK", "DC=MyDomain,DC=local"),
("Location_", "US_", "Computers US", "DC=MyDomain,DC=local"),
("Department_", "IT_", "IT", "OU=Computers UK,DC=MyDomain,DC=local"),
("Department_", "Sales_", "Sales", "OU=Computers UK,DC=MyDomain,DC=local"),
("Department_", "HR_", "HR", "OU=Computers UK,DC=MyDomain,DC=local")

#define constants
#$const_exportFile="c:\\resultFile.csv"
#$const_vCenterServer="MyVC"
$const_vCenterServer=$args[0]
$const_exportFile=$args[1]
$const_objectType="VirtualMachine"

# parse maps and extract categories for furture use
$categories=@()
foreach($map in $maps)
{
   $c=$map[0]
   $exist=0
   foreach($gcat in $categories)
   {
       if($gcat -eq $c)
       {
           $exist=1
           break
       }    
   }
   if($exist -eq 0) { $categories+=$c }
}
#end of extracting categories

# initialize active directory
$root=[adsi]''
$query=new-object system.directoryservices.directorysearcher
$query.searchRoot = $root
$query.searchScope="subtree"

# store results here
$result=@()

foreach($map in $maps)
{
   # initialize variables
   $category=$map[0]
   $group=$map[1]
   $ou=$map[2]
   $path=$map[3]

   # find organization unit
   $query.filter="(ou=$ou)"
   $node=$query.findall() | where {$_.path -match $path}    

   # find computers
   $cq=new-object system.directoryservices.directorysearcher
   $cq.SearchRoot=$node.psbase.GetDirectoryEntry()
   $cq.SearchScope="subtree"
   $cq.filter="(objectClass=computer)"    
   $computers=$cq.findall()

   foreach($computer in $computers)
   {
       $resultRow=@{} | select vCenterServer, ObjectType, ComputerName, IPAddress, Name
       $resultRow.vCenterServer=$const_vCenterServer
       $resultRow.ObjectType=$const_objectType
       $resultRow.ComputerName=$computer.psbase.properties.name[0]
       
       # make a row with specified groups and categories for each computer
       foreach($c in $categories)
       {
           $g=""
           if($c -eq $category) { $g=$group }
           $resultRow=$resultRow | select *, @{n=$c; e={$g}}
       }

       # find out add this row or just modify group for category
       $na=1
       foreach($rr in $result)
       {
           # if computer already exists in result, than modify specified category
           if($rr.ComputerName -eq $resultRow.ComputerName)
           {
               $na=0
               $rr.$category=$group
           }
       }
       # if computer doesn't exist in result add computer with specified category and group
       if($na -eq 1)
       {
           $result+=$resultRow
       }
   }
}

$result | sort name | export-csv $const_exportFile -notypeinformation -delimiter ";"
#$result

Step 2. Create a Batch File That Calls the Script

Create a batch file named Script.bat that runs a command to call AD2CSV.ps1 and output its results to the resultFile.csv file. An example of the command for the batch file is provided below:

cmd /c start /wait powershell -command "& 'C:\AD2CSV.ps1' MyVC c:\resultFile.csv"

Note that you need to replace 'MyVC' with the name of the vCenter Server you are using.

Step 3. Specify Paths to the .CSV and Script Files

Specify paths to the CSV file and the script file in Veeam ONE Business View:

  1. Open Veeam Backup & Replication.
  2. Open the Configuration tab.
  3. In the Configuration menu on the left, click Import/Export.
  4. In the Specify a CSV file to be used for tags synchronization field, specify a path to the resultFile.csv file.
  5. Select the Execute this script before synchronizing with a CSV file check box and specify a path to the Script.bat file in the field below.

Synchronize Data with a Sample Script

Expected Result

When Veeam ONE runs data collection for Veeam ONE Business View, it will call the batch file. The batch file will execute a script that will create an output CSV file with the categorization data. Data from this CSV file will be imported in Veeam ONE Business View. This way Veeam ONE Business View categorization will be synchronized with Active Directory.

You can also configure the synchronization without the script file. In this case, you will need to specify the path to the CSV file and update it manually when needed. However, using the script file allows you automate these updates if your environment changes frequently.

Veeam Large Logo

Deployment Guide

Deployment for Large-Scale Environments

Monitor User Guide

Reporter User Guide

Business View User Guide

Multi-Tenant Monitoring and Reporting

Working with Alarms

Veeam Backup & Replication Documentation

Veeam Agent for Windows Documentation

Veeam Agent for Linux Documentation

Veeam Management Pack Documentation