Backup and Export Distributed Switch configuration

The below script was prepared to Backup and Export Distributed Switch configuration:

Connect-VIServer -Server vCenter_FQDN/IP_Address -Credential (Get-Credential)
$vDSwitchDetails = Get-VDSwitch
$vDSwitchNames = $vDSwitchDetails.Name
$datestamp = Get-Date -Format “MM-dd-yyyy”
Foreach ($vDSwitchName in $vDSwitchNames)
{
$DestiationDir = “C:\Users\Administrator\Desktop\Scripts\vDSExport\”+ $datestamp + “\” + $vDSwitchName + “\”
New-Item -Path $DestiationDir -ItemType “Directory” -Force
$filename= $DestiationDir + $vDSwitchName + “.zip”
Get-VDSwitch -Name $vDSwitchName | Export-VDSwitch -Description “vDS Backup” -Destination $filename
}
Disconnect-VIServer -Confirm:$false

Export LUN IDs with Path Selection Policy

Featured

In this post we are sharing a PowerCLI script that we used to export a list of LUNs attached to ESXi hosts in a cluster along with the details of Path Selection Policy selected for the LUN and CommandsToSwitchPath parameter set for the LUNs.

Script was tested on below versions:

  • PowerCLI version 11.5.0 build 14912921
  • vSphere 6.7U3

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred

$getCluster = Get-Cluster -Name "Cluster_Name"
$getESXis = $getCluster | Get-VMHost
$printluns=@()

foreach ($getESXi in $getESXis)
{
    $getLUNsforESXi = Get-VMhost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
    $printluns = $printluns + $getLUNsforESXi
}

$printluns | Export-Csv C:\users\Administrator\Desktop\PathtoSaveFile.csv -NoTypeInformation 

Disconnect-VIServer -Confirm:$false

Just replace the vCenter_Server_IP_Address/FQDN, Cluster_Name and Path of CSV File and run the script to generate a report of LUNs mapped to all ESXi hosts in a vSphere cluster in your environment. BOOM!!

Happy Scripting!!

VMware Aria Operations – Backup & Export Configuration

Featured

In this blog we have covered the 2 methods of taking Backup of your VMware Aria Operations (vRealize Operations Manager) configuration.

VMware Aria Operations introduced a feature called Content Management in version 8.2 back in October 2020.

Content Management helps the Customers to Backup and Export their configuration of VMware Aria Operations which can be further used to restore the configuration like Dashboards, Views, Report Templates, Supremetrics and a lot more in case you run into issues with the deployment.

We have covered two methods of taking a Backup and Export of VMware Aria Operations Configuration – First one, using the Content Management Tab under Administration in VMware Aria Operations UI and Second one, using a Python Script which makes use of the native APIs of Aria Operations.

Python script which we have developed has been tested on Python 3.10.10 version and Aria Operations 8.10 version. This script can also be scheduled as a Scheduled Task to take periodic configuration backups.

Method -1: Content Management Tab under Administration in VMware Aria Operations UI

Method -2: Python Script which uses native APIs of Aria Operations

#!/usr/local/bin python3

import requests, json, urllib3, datetime, time, os, zipfile, shutil

from requests.auth import HTTPBasicAuth
from datetime import datetime


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

base_url = 'https://vrops80-weekly.cmbu.local/suite-api/api'
token_url = base_url + '/auth/token/acquire'
headers =  {"Content-Type":"application/json", "Accept":"application/json"}
body = {
    "username": "admin",
    "password": "VMware1!",
    "authSource": "local"
    }

token_api_response = requests.post(token_url, headers=headers, json=body, verify=False)

token_api_response = token_api_response.json()

vRealize_ops_token = token_api_response["token"]

print("vRealize Ops Token: " + vRealize_ops_token)

content_export_request_url = base_url + '/content/operations/export/'

headers = {"Content-Type":"application/json", "Accept":"application/json", "EncryptionPassword": "Aman@123456789", "Authorization": "vRealizeOpsToken " + vRealize_ops_token}

body = {
  "scope" : "CUSTOM",
  "contentTypes" : [ "DASHBOARDS", "VIEW_DEFINITIONS", "REPORT_DEFINITIONS", "REPORT_SCHEDULES", "CONFIG_FILES", "ALERT_DEFINITIONS", "SYMPTOM_DEFINITIONS", "RECOMMENDATION_DEFINITIONS",  "NOTIFICATION_RULES", "PAYLOAD_TEMPLATES", "POLICIES", "CUSTOM_GROUPS", "SUPER_METRICS", "COMPLIANCE_SCORECARDS", "AUTH_SOURCES", "USERS", "USER_GROUPS", "ROLES", "INTEGRATIONS", "HTTP_PROXIES", "OUTBOUND_SETTINGS", "COST_DRIVERS", "SDMP_CUSTOM_SERVICES", "SDMP_CUSTOM_APPLICATIONS", "DISCOVERY_RULES", "APP_DEF_ASSIGNMENTS", "CUSTOM_PROFILES", "GLOBAL_SETTINGS"  ],
  "Password" : "12345"
  }

content_export_response = requests.post(content_export_request_url, headers=headers, json=body, verify=False)

content_export_response = content_export_response.json()

print("Sleeping for 60 seconds")

time.sleep(60)

export_zip_url = base_url + '/content/operations/export/zip'

headers = {"Content-Type":"application/json", "Accept":"application/json", "Authorization": "vRealizeOpsToken " + vRealize_ops_token}

export_zip_response = requests.get(export_zip_url, headers=headers, verify=False)

current_datetime = datetime.now()
str_current_datetime = str(current_datetime)
file_name = "./vROpsContentBackup/" + str_current_datetime+".zip"
print(file_name)
with open(file_name, 'wb') as zipFile:
    zipFile.write(export_zip_response.content)

For the detailed process to Backup and Export VMware Aria Operations Configuration please watch our video:

I hope this blog was informative for you, stay tuned for our upcoming blogs. Happy Learning!!

#vmware #aria #operations #vROps #manager #content #management #public #private #hybrid #cloud #backup #export

VMware Aria Operations – Backup & Export Configuration

Featured

In this blog we have covered the 2 methods of taking Backup of your VMware Aria Operations (vRealize Operations Manager) configuration.

VMware Aria Operations introduced a feature called Content Management in version 8.2 back in October 2020.

Content Management helps the Customers to Backup and Export their configuration of VMware Aria Operations which can be further used to restore the configuration like Dashboards, Views, Report Templates, Supremetrics and a lot more in case you run into issues with the deployment.

We have covered two methods of taking a Backup and Export of VMware Aria Operations Configuration – First one, using the Content Management Tab under Administration in VMware Aria Operations UI and Second one, using a Python Script which makes use of the native APIs of Aria Operations.

Python script which we have developed has been tested on Python 3.10.10 version and Aria Operations 8.10 version. This script can also be scheduled as a Scheduled Task to take periodic configuration backups.

Method -1: Content Management Tab under Administration in VMware Aria Operations UI

Method -2: Python Script which uses native APIs of Aria Operations

#!/usr/local/bin python3
import requests, json, urllib3, datetime, time, os, zipfile, shutil
from requests.auth import HTTPBasicAuth
from datetime import datetime
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
base_url = 'https://vrops80-weekly.cmbu.local/suite-api/api'
token_url = base_url + '/auth/token/acquire'
headers =  {"Content-Type":"application/json", "Accept":"application/json"}
body = {
    "username": "admin",
    "password": "VMware1!",
    "authSource": "local"
    }
token_api_response = requests.post(token_url, headers=headers, json=body, verify=False)
token_api_response = token_api_response.json()
vRealize_ops_token = token_api_response["token"]
print("vRealize Ops Token: " + vRealize_ops_token)
content_export_request_url = base_url + '/content/operations/export/'
headers = {"Content-Type":"application/json", "Accept":"application/json", "EncryptionPassword": "Aman@123456789", "Authorization": "vRealizeOpsToken " + vRealize_ops_token}
body = {
  "scope" : "CUSTOM",
  "contentTypes" : [ "DASHBOARDS", "VIEW_DEFINITIONS", "REPORT_DEFINITIONS", "REPORT_SCHEDULES", "CONFIG_FILES", "ALERT_DEFINITIONS", "SYMPTOM_DEFINITIONS", "RECOMMENDATION_DEFINITIONS",  "NOTIFICATION_RULES", "PAYLOAD_TEMPLATES", "POLICIES", "CUSTOM_GROUPS", "SUPER_METRICS", "COMPLIANCE_SCORECARDS", "AUTH_SOURCES", "USERS", "USER_GROUPS", "ROLES", "INTEGRATIONS", "HTTP_PROXIES", "OUTBOUND_SETTINGS", "COST_DRIVERS", "SDMP_CUSTOM_SERVICES", "SDMP_CUSTOM_APPLICATIONS", "DISCOVERY_RULES", "APP_DEF_ASSIGNMENTS", "CUSTOM_PROFILES", "GLOBAL_SETTINGS"  ],
  "Password" : "12345"
  }
content_export_response = requests.post(content_export_request_url, headers=headers, json=body, verify=False)
content_export_response = content_export_response.json()
print("Sleeping for 60 seconds")
time.sleep(60)
export_zip_url = base_url + '/content/operations/export/zip'
headers = {"Content-Type":"application/json", "Accept":"application/json", "Authorization": "vRealizeOpsToken " + vRealize_ops_token}
export_zip_response = requests.get(export_zip_url, headers=headers, verify=False)
current_datetime = datetime.now()
str_current_datetime = str(current_datetime)
file_name = "./vROpsContentBackup/" + str_current_datetime+".zip"
print(file_name)
with open(file_name, 'wb') as zipFile:
    zipFile.write(export_zip_response.content)

For the detailed process to Backup and Export VMware Aria Operations Configuration please watch our video:

I hope this blog was informative for you, stay tuned for our upcoming blogs. Happy Learning!!

#vmware #aria #operations #vROps #manager #content #management #public #private #hybrid #cloud #backup #export

Export vRA 7.6 Reservation Details

In this post we are sharing a PowerShell script which uses PowervRA Module to export a list of vRealize Automation 7.6 Reservations along with their respective usage.

Script was tested on below versions:

  • PowervRA 3.7.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server 'vRA_FQDN' -Username $cred.UserName -Password $cred.Password -Tenant "Tenant_Name" -IgnoreCertRequirements
$BGReserves = Get-vRAReservation | Select CreatedDate, Name, TenantId, ExtensionData
$fetchVMDetails= Get-vRAResource | where {$_.ResourceType -eq "Infrastructure.Virtual"}
$output = @()
    foreach($BGReserve in $BGReserves)
    {

        $ReserveVMDetails = ($fetchVMDetails | where {$_.Data.MachineReservationName -eq $BGReserve.name}).Data  | Select MachineName, MachineMemory, MachineStorage
    foreach ($ReserveVMDetail in $ReserveVMDetails)
    {
        $MachineQuotaUsed = $MachineQuotaUsed + 1
        $MemoryUsedinMB = $MemoryUsedinMB + $ReserveVMDetail.MachineMemory
        $StorageUsedinGB = $StorageUsedinGB + $ReserveVMDetail.MachineStorage
    }
    $MemoryUsedinGB = $MemoryUsedinMB/1024
        $fetchReserveDetails = $BGReserve.ExtensionData.entries
        $fetchQuotavalue = ($fetchReserveDetails |  where {$_.key -eq "machineQuota"}).value.value
        $BGReserve | Add-Member -NotePropertyName MachineQuota -NotePropertyValue $fetchQuotavalue
        $fetchMemoryReserve = (($fetchReserveDetails | where {$_.key -eq "reservationMemory"}).value.values.entries | where {$_.key -eq "memoryReservedSizeMb"}).value.value/1024
        $BGReserve | Add-Member -NotePropertyName MemoryReservedinGB -NotePropertyValue $fetchMemoryReserve
        $fetchStorageReserve = (($fetchReserveDetails | where {$_.key -eq "reservationStorages"}).value.items.values.entries | where {$_.key -eq "storageReservedSizeGB"}).value.value
        $BGReserve | Add-Member -NotePropertyName StorageReservedinGB -NotePropertyValue $fetchStorageReserve
        $MachineQuotaAllocated = $MachineQuotaAllocated + $fetchQuotavalue
        $BGReserve | Add-Member -NotePropertyName MachinesAllocated -NotePropertyValue $MachineQuotaUsed
        $MemoryAllocatedinGB = $MemoryAllocatedinGB + $fetchMemoryReserve
        $BGReserve | Add-Member -NotePropertyName MemoryAllocatedinGB -NotePropertyValue $MemoryUsedinGB
        $StorageAllocatedinGB = $StorageAllocatedinGB + $fetchStorageReserve
        $BGReserve | Add-Member -NotePropertyName StorageAllocatedinGB -NotePropertyValue $StorageUsedinGB
        $MachineQuotaAllocated = 0
        $MemoryAllocatedinGB = 0
        $StorageAllocatedinGB = 0
        $MemoryUsedinMB = 0
        $MemoryUsedinGB = 0
        $StorageUsedinGB = 0
        $MachineQuotaUsed = 0
    }

$output = $BGReserves | Select Name, CreatedDate, TenantId, MachineQuota, MachinesAllocated, MemoryReservedinGB, MemoryAllocatedinGB, StorageReservedinGB, StorageAllocatedinGB
$output | FT -AutoSize -Wrap

$output | Export-Csv "Path_To_Target.csv" -NoTypeInformation

Disconnect-vRAServer -Confirm:$false

Just replace the vRA_FQDN, Tenant_Name, Path_To_Target.csv and TenantAdmin Credentials to run the script & to generate a report of vRealize Automation 7.6 Reservations in your environment. BOOM!!

Happy Scripting!!

Script to Export VI Permissions

Featured

There was a requirement in one of the projects to export permissions assigned to each Virtual Machine hosted in a vSphere Environment. We wrote a PowerCLI script to fetch the list of users along with the Role assigned to each user and export these details to a CSV file.

Requirements:

  • PowerCLI
  • PowerShell 5.1 or later

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred
$vms = Get-VM
$output = New-Object System.Collections.ArrayList($null)
$vmpermission = @()
foreach ($vm in $vms)
{
    $permissions = $vm | Get-VIPermission | Get-Unique
    Foreach ($permission in $permissions)
    {
        $formatpermission = $permission.Principal + " (" + $permission.Role + ")"
        $permission | Add-Member -NotePropertyName FormatPermission -NotePropertyValue $formatpermission
    }
    $vmpermission = [pscustomobject]@{VMName=$vm.Name;Role=$permissions.FormatPermission  -join ', '}
    [void]($output.Add($vmpermission))
}

$output | Export-csv C:\Users\VMPermissionsExport.csv -NoTypeInformation

Just replace the vCenter_Server_IP_Address/FQDN and Path of CSV File and run the script to export VI Permissions assigned to each Virtual Machine in vSphere environment. BOOM!!

Happy Scripting!!

Export vRA 7.6 Reservation Details

In this post we are sharing a PowerShell script which uses PowervRA Module to export a list of vRealize Automation 7.6 Reservations along with their respective usage.

Script was tested on below versions:

  • PowervRA 3.7.0
  • PowerShell 5.1 or later

Script:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$cred = Get-Credential
Connect-vRAServer -Server 'vRA_FQDN' -Username $cred.UserName -Password $cred.Password -Tenant "Tenant_Name" -IgnoreCertRequirements
$BGReserves = Get-vRAReservation | Select CreatedDate, Name, TenantId, ExtensionData
$fetchVMDetails= Get-vRAResource | where {$_.ResourceType -eq "Infrastructure.Virtual"}
$output = @()
    foreach($BGReserve in $BGReserves)
    {

        $ReserveVMDetails = ($fetchVMDetails | where {$_.Data.MachineReservationName -eq $BGReserve.name}).Data  | Select MachineName, MachineMemory, MachineStorage
    foreach ($ReserveVMDetail in $ReserveVMDetails)
    {
        $MachineQuotaUsed = $MachineQuotaUsed + 1
        $MemoryUsedinMB = $MemoryUsedinMB + $ReserveVMDetail.MachineMemory
        $StorageUsedinGB = $StorageUsedinGB + $ReserveVMDetail.MachineStorage
    }
    $MemoryUsedinGB = $MemoryUsedinMB/1024
        $fetchReserveDetails = $BGReserve.ExtensionData.entries
        $fetchQuotavalue = ($fetchReserveDetails |  where {$_.key -eq "machineQuota"}).value.value
        $BGReserve | Add-Member -NotePropertyName MachineQuota -NotePropertyValue $fetchQuotavalue
        $fetchMemoryReserve = (($fetchReserveDetails | where {$_.key -eq "reservationMemory"}).value.values.entries | where {$_.key -eq "memoryReservedSizeMb"}).value.value/1024
        $BGReserve | Add-Member -NotePropertyName MemoryReservedinGB -NotePropertyValue $fetchMemoryReserve
        $fetchStorageReserve = (($fetchReserveDetails | where {$_.key -eq "reservationStorages"}).value.items.values.entries | where {$_.key -eq "storageReservedSizeGB"}).value.value
        $BGReserve | Add-Member -NotePropertyName StorageReservedinGB -NotePropertyValue $fetchStorageReserve
        $MachineQuotaAllocated = $MachineQuotaAllocated + $fetchQuotavalue
        $BGReserve | Add-Member -NotePropertyName MachinesAllocated -NotePropertyValue $MachineQuotaUsed
        $MemoryAllocatedinGB = $MemoryAllocatedinGB + $fetchMemoryReserve
        $BGReserve | Add-Member -NotePropertyName MemoryAllocatedinGB -NotePropertyValue $MemoryUsedinGB
        $StorageAllocatedinGB = $StorageAllocatedinGB + $fetchStorageReserve
        $BGReserve | Add-Member -NotePropertyName StorageAllocatedinGB -NotePropertyValue $StorageUsedinGB
        $MachineQuotaAllocated = 0
        $MemoryAllocatedinGB = 0
        $StorageAllocatedinGB = 0
        $MemoryUsedinMB = 0
        $MemoryUsedinGB = 0
        $StorageUsedinGB = 0
        $MachineQuotaUsed = 0
    }

$output = $BGReserves | Select Name, CreatedDate, TenantId, MachineQuota, MachinesAllocated, MemoryReservedinGB, MemoryAllocatedinGB, StorageReservedinGB, StorageAllocatedinGB
$output | FT -AutoSize -Wrap

$output | Export-Csv "Path_To_Target.csv" -NoTypeInformation

Disconnect-vRAServer -Confirm:$false

Just replace the vRA_FQDN, Tenant_Name, Path_To_Target.csv and TenantAdmin Credentials to run the script & to generate a report of vRealize Automation 7.6 Reservations in your environment. BOOM!!

Happy Scripting!!

Export LUN IDs with Path Selection Policy

Featured

In this post we are sharing a PowerCLI script that we used to export a list of LUNs attached to ESXi hosts in a cluster along with the details of Path Selection Policy selected for the LUN and CommandsToSwitchPath parameter set for the LUNs.

Script was tested on below versions:

  • PowerCLI version 11.5.0 build 14912921
  • vSphere 6.7U3

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred

$getCluster = Get-Cluster -Name "Cluster_Name"
$getESXis = $getCluster | Get-VMHost
$printluns=@()

foreach ($getESXi in $getESXis)
{
    $getLUNsforESXi = Get-VMhost $getESXi | Get-ScsiLun -LunType disk | Select VMHost, CanonicalName, MultipathPolicy, CommandsToSwitchPath
    $printluns = $printluns + $getLUNsforESXi
}

$printluns | Export-Csv C:\users\Administrator\Desktop\PathtoSaveFile.csv -NoTypeInformation 

Disconnect-VIServer -Confirm:$false

Just replace the vCenter_Server_IP_Address/FQDN, Cluster_Name and Path of CSV File and run the script to generate a report of LUNs mapped to all ESXi hosts in a vSphere cluster in your environment. BOOM!!

Happy Scripting!!

Script to Export VI Permissions

Featured

There was a requirement in one of the projects to export permissions assigned to each Virtual Machine hosted in a vSphere Environment. We wrote a PowerCLI script to fetch the list of users along with the Role assigned to each user and export these details to a CSV file.

Requirements:

  • PowerCLI
  • PowerShell 5.1 or later

Script:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$cred = Get-Credential
Connect-VIServer vCenter_IP/FQDN -Credential $cred
$vms = Get-VM
$output = New-Object System.Collections.ArrayList($null)
$vmpermission = @()
foreach ($vm in $vms)
{
    $permissions = $vm | Get-VIPermission | Get-Unique
    Foreach ($permission in $permissions)
    {
        $formatpermission = $permission.Principal + " (" + $permission.Role + ")"
        $permission | Add-Member -NotePropertyName FormatPermission -NotePropertyValue $formatpermission
    }
    $vmpermission = [pscustomobject]@{VMName=$vm.Name;Role=$permissions.FormatPermission  -join ', '}
    [void]($output.Add($vmpermission))
}

$output | Export-csv C:\Users\VMPermissionsExport.csv -NoTypeInformation

Just replace the vCenter_Server_IP_Address/FQDN and Path of CSV File and run the script to export VI Permissions assigned to each Virtual Machine in vSphere environment. BOOM!!

Happy Scripting!!

Backup and Export Distributed Switch configuration

The below script was prepared to Backup and Export Distributed Switch configuration:

Connect-VIServer -Server vCenter_FQDN/IP_Address -Credential (Get-Credential)
$vDSwitchDetails = Get-VDSwitch
$vDSwitchNames = $vDSwitchDetails.Name
$datestamp = Get-Date -Format “MM-dd-yyyy”
Foreach ($vDSwitchName in $vDSwitchNames)
{
$DestiationDir = “C:\Users\Administrator\Desktop\Scripts\vDSExport\”+ $datestamp + “\” + $vDSwitchName + “\”
New-Item -Path $DestiationDir -ItemType “Directory” -Force
$filename= $DestiationDir + $vDSwitchName + “.zip”
Get-VDSwitch -Name $vDSwitchName | Export-VDSwitch -Description “vDS Backup” -Destination $filename
}
Disconnect-VIServer -Confirm:$false