For one of my customers we were optimizing actions, configurations and connections between the datacenters. One of the goals was to connect the VDIs in the datacenter to supporting components in the same datacenter while using one central image (PVS vDisk in this case). Not a big thing in my mind, but shortly somebody asked something similar. So probably there is a demand for it. In this short quick article I will share what I have set-up.

Firstly you need to find a way to determine in which data center the VDA is located. Luckily based companies/organizations add a number or something simulator in the name to distinguish to VDIs. This customer was using VD1xxx and VD2xxx naming convention where the 1 and 2 are based on the datacenter. So the idea is to create a script that determines this unique number and perform actions on the outcome the determination of the VDI locations.

Actually this is not so hard, I used the $Env:Computername available variable and using the substring method to strip the first 3 characters.

Those 3 characters are stored in a variable and compared with a defined variable which holds the predefined datacenter location unique character set. If it matches you can configure the required actions. You can think off settings registry values, specific configuration files, copy files and so on. Actually anything you need. The “script” is actually pretty

#---------------------------------------------------------------------------------------
# Script: ActionsPerDatacenter.ps1
# Script to determine VDA data center and perfom actions based on that
# Creator: Wilco van Bragt
# Creation Date: 10-09-2020
#---------------------------------------------------------------------------------------
# Version: 0.1
# By: Wilco van Bragt
# Date: 10-09-2020
# Changes: Initial Release
#---------------------------------------------------------------------------------------

# Define Infrastructure Dependent Variables
#---------------------------------
$DC1UC="<<UniqueDC1Chartarestic>>"
$DC2UC="<<UniqueDC2Chartarestic>>"

#Determine VDA Name and trim to first 3 characters to determine DC location
#---------------------------------
$First3CharVDA = $Env:Computername.substring(0,3)

#IF VDA is located in DC1 do DC1 ActionsPerDatacenter
#---------------------------------
If (($First3CharVDA).equals($DC1UC))
                    {
                    <<DEFINE Actions for DC1>>
                    }

#IF VDA is located in DC2 do DC2 ActionsPerDatacenter
#---------------------------------             
If(($First3CharVDA).equals($DC2UC))
                    {
                    <<DEFINE Actions for DC1>>
                   }

Logically the script need to be run on the VDI at the moment the machine starts-up. We decided that a scheduled task at start-up was the best idea. Therefore I set-up a simple script (where I borrowed the configuration of the scheduled taks from the Internet. We run this during the creation of the vDisk using the automation tools available.

#---------------------------------------------------------------------------------------
# Script: SetScheduledtaskatstart.ps1
# Script to to set a scheduled task at logon
# Creator: Wilco van Bragt
# Creation Date: 10-09-2020
#---------------------------------------------------------------------------------------

Copy-Item "\\servern\share\ActionsPerDatacenter.ps1" -Destination "C:\tools\ ActionsPerDatacenter.ps1"

$Trigger= $Trigger= New-ScheduledTaskTrigger -AtStartup

$User= "NT AUTHORITY\SYSTEM"

$Action= New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "C:\tools\ActionsPerDatacenter.ps1"

Register-ScheduledTask -TaskName "Actions Per Datacenter" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force