Showing posts with label PowerCli. Show all posts
Showing posts with label PowerCli. Show all posts

Monday, July 25, 2022

PowerCli to get all the needed data for a VM

 We are going to migrate one of our classical environments which doesn't have NSX to a new env. which has NSX.

To start doing some analysis, we will need to collect these data :

1. all the VMs in the env.
2. The OS
3. The power status
4. VLAN number 
5. The CPU and memory of the VMs
6. The size of the VM in GB without decimals 
7. Cluster
8. IP address
9. Number of NICs


here in this GUT repo you will find the powercli script The PowerCli Script



























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"
 }



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...