Monday, May 30, 2022

Backup VDS and DRS rules and groups

 We are going today to do a backup for the vDS of the vCenter and backup the DRS rules and groups


1. The first step is to encrypt your administrator@vsphere.local password, you will find the script on the Github How to encrypt the password

2. The second step is to use your encrypted password in this script How to backup vDS and DRS rules

3. Schedule this script in the task scheduler of your jump box.




Note: I highly recommend to use a service account to execute the backup scripts. 

Thursday, May 19, 2022

vSphere Tags after Cross vCenter vMotion

We will explain here how you can reapply the vSphere Tags after you migrate a VM from one vCenter to another or even when you use VEEAM or any other replication tool to replicate a VM from one vCenter to another vCenter


Before executing this script you will need to create 2 folders in the 2 vCenters with the same name. and put the machines under these folders. because the main Idea of the script is getting the VMs under a certain folder and collect their TAGs , and then login to the other vCenter and search for the collected VMs and start to apply the TAGs on them. you also will need to make sure that the TAGs exist on the destination VC (The script will not create the TAGs , it will apply them only)


Import-Module VMware.VimAutomation.Core
 
$vCenterIP = "First vCenter"
$FOLDERNAME = 'XXXX'          ##Change XXXX with folder Namer###
Connect-VIServer $vCenterIP

$tagsall = @()

foreach($machine in $machines = Get-Folder -Name $FOLDERNAME | Get-VM){
$tagsall+=@(Get-TagAssignment -Entity $machine.name)
}
$tagsall

sleep 10

Disconnect-VIServer $vCenterIP -confirm:$false


1. Don't close your Powershell window. 

2. Start to do the cross vCenter vmotion.

3. After you finish from all the VMs.

4. Execute the below script.


$vCenterIP = "Second vCenter"
Connect-VIServer $vCenterIP -User $vCenterUser -Password $vCenterPass 

$tagsallnew = $tagsall | select Tag,Entity

for($i = 0; $i -lt $tagsallnew.length; $i++){

 $tag = Get-Tag -name $tagsallnew[$i].tag.name -Category $tagsallnew[$i].tag.Category.name   -Server "Second vCenter"
 $vm = get-vm -name $tagsallnew[$i].Entity.Name   -Server "Second vCenter"

 New-TagAssignment -Tag $tag  -Entity $vm -Server "Second vCenter"
 }



Sunday, May 15, 2022

Set Env. variable for Terraform on Windows

 We will explain how you can put your Terraform variable in your windows environment variables.

Note: you can for example put your VMC Token in your windows variables. This will avoid you from 2 things:

1. Put the token in the code itself, which is not recommended at all for security reasons.

2. Write the token every time when you plan or apply the code.


Note: The below variable is changeable based on the variable name in your code.


Set-Item -Path env:TF_VAR_token -Value “token_value“


To set the backend access key and secret key:


Set-Item -Path env:AWS_ACCESS_KEY_ID -Value "xyxyxyxyxyx12345"

Set-Item -Path env:AWS_SECRET_ACCESS_KEY -Value "abcabcabcabcabcabcabc12345"


Source: https://www.terraform.io/language/settings/backends/s3 

NSX-T (local log in) with VIDM integration

We will explain how to log in with a local account to your NSX-T which integrated with VIDM. We integrated our NSX-T into the VIDM. We had a...