Showing posts with label vcenter. Show all posts
Showing posts with label vcenter. Show all posts

Friday, April 15, 2022

How to configure SSL in vCenter 6.7

First take vCenter VM snapshot for backup purpose.

Take note of host where the vCenter VM resides while starting the activity.

Take Access of vCenter Shell to create a certificate CSR request.

root@prod-vcsa71 [ ~ ]# /usr/lib/vmware-vmca/bin/certificate-manager

Now copy the CSR file content in notepad file and save as .txt or .csr

Once have the CSR, generate a certificate by using this CSR.



Now copy the certificate file to the vcenter along with the RootCA certificate.


Start process for Import the certificate.

root@prod-vcsa71 [ ~ ]# /usr/lib/vmware-vmca/bin/certificate-manager



Provide certificate file location as per below the snip, Once all details provided it will take around 20-30 mins depending on the vCenter performance.



Once all required services started properly it will give the status as mentioned below.



Now try to access the vCenter from WebGUI, It is now secure.



Also try to access the vCenter Appliance Management Interface, It will still show the certificate error, to resolve this, restart the vami https service as mentioned below.



root@prod-vcsa71 [ /opt ]# /sbin/service vami-lighttpd restart



Now again try to access the vCenter Appliance Management Interface, It will also start with SSL certificate.




To check service status: 

root@prodvcenter [ ~ ]# service-control --status --all

To check logs if anything fails.

root@prodvcenter [ ~ ]# tail -f /var/log/vmware/vmcad/certificate-manager.log

If Certificate import files due to content-library service fails to start, increase Start time in below mentioned file from 300 to 600sec.

root@prodvcenter [ ~ ]# vi /etc/vmware/vmware-vmon/svcCfgfiles/vdcs.json




Wednesday, May 30, 2018

Get Complete Virtual Machine inventory of vcenter using vmwarepowercli

Copy below given script and save it as filename.ps1

execute the same script your output of this script will be saved at "c:\vminventory.csv"


You will get below mentioned information from this script.

1.  VMName
2.  IP Address
3.  Domain Name
4.  Real-OS
5.  vCPU
6.  RAM(GB)
7.  Total-HDD(GB)
8.  HDDs(GB)
9.  Datastore
10. Partition/Size
11. Hardware Version
12. PowerState
13. Setting-OS
14. EsxiHost
15. vCenter Server
16. Folder
17. MacAddress
18. VMX
19. VMDK
20. VMTools Status
21. VMTools Version
22. VMTools Version Status
23. VMTools Running Status
24. SnapShots
25. DataCenter
26. vNic
27. PortGroup
28. RDMs


#Add-PSSnapin vmware.vimautomation.core
Connect-Viserver    
#####################################  
 ## http://kunaludapi.blogspot.com  
 ## Version: 1  
 ## Tested this script on  
 ##  1) Powershell v3  
 ##  2) Powercli v5.5  
 ##  3) Vsphere 5.x  
 ####################################
 function Get-VMinventory {  
 function Get-RDMDisk {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $RDMInfo = Get-VM -Name $VMName | Get-HardDisk -DiskType RawPhysical, RawVirtual  
         $Result = foreach ($RDM in $RDMInfo) {  
          "{0}/{1}/{2}/{3}"-f ($RDM.Name), ($RDM.DiskType),($RDM.Filename), ($RDM.ScsiCanonicalName)     
         }  
         $Result -join (", ")  
 }  
 function Get-vNicInfo {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $vNicInfo = Get-VM -Name $VMName | Get-NetworkAdapter  
         $Result = foreach ($vNic in $VnicInfo) {  
           "{0}={1}"-f ($vnic.Name.split("")[2]), ($vNic.Type)  
         }  
         $Result -join (", ")  
 }  
 function Get-InternalHDD {  
   [CmdletBinding()]  
   param (  
     [Parameter(Mandatory=$True)]  
     [string[]]$VMName  
     )  
         $VMInfo = Get-VMGuest -VM $VMName # (get-vm $VMName).extensiondata  
         $InternalHDD = $VMInfo.ExtensionData.disk   
         $result = foreach ($vdisk in $InternalHDD) {  
           "{0}={1}GB/{2}GB"-f ($vdisk.DiskPath), ($vdisk.FreeSpace /1GB -as [int]),($vdisk.Capacity /1GB -as [int])  
         }  
         $result -join (", ")  
 }  
   foreach ($vm in (get-vm)) {  
     $props = @{'VMName'=$vm.Name;  
           'IP Address'= $vm.Guest.IPAddress -join ","; #$VM.ExtensionData.Summary.Guest.IpAddress  
           'PowerState'= $vm.PowerState;  
           'Domain Name'= ($vm.ExtensionData.Guest.Hostname -split '\.')[1,2] -join '.';            
           'vCPU'= $vm.NumCpu;  
           'RAM(GB)'= $vm.MemoryGB;  
           'Total-HDD(GB)'= $vm.ProvisionedSpaceGB -as [int];  
           'HDDs(GB)'= ($vm | get-harddisk | select-object -ExpandProperty CapacityGB) -join " + "            
           'Datastore'= (Get-Datastore -vm $vm) -split ", " -join ", ";  
           'Partition/Size' = Get-InternalHDD -VMName $vm.Name  
           'Real-OS'= $vm.guest.OSFullName;  
           'Setting-OS' = $VM.ExtensionData.summary.config.guestfullname;  
           'EsxiHost'= $vm.VMHost;  
           'vCenter Server' = ($vm).ExtensionData.Client.ServiceUrl.Split('/')[2].trimend(":443")  
           'Hardware Version'= $vm.Version;  
           'Folder'= $vm.folder;  
           'MacAddress' = ($vm | Get-NetworkAdapter).MacAddress -join ", ";  
           'VMX' = $vm.ExtensionData.config.files.VMpathname;  
           'VMDK' = ($vm | Get-HardDisk).filename -join ", ";  
           'VMTools Status' = $vm.ExtensionData.Guest.ToolsStatus;  
           'VMTools Version' = $vm.ExtensionData.Guest.ToolsVersion;  
           'VMTools Version Status' = $vm.ExtensionData.Guest.ToolsVersionStatus;  
           'VMTools Running Status' = $vm.ExtensionData.Guest.ToolsRunningStatus;  
           'SnapShots' = ($vm | get-snapshot).count;  
           'DataCenter' = $vm | Get-Datacenter;  
           'vNic' = Get-VNICinfo -VMName $vm.name;  
           'PortGroup' = ($vm | Get-NetworkAdapter).NetworkName -join ", ";  
           'RDMs' = Get-RDMDisk -VMName $VM.name  
           #'Department'= ($vm | Get-Annotation)[0].value;  
           #'Environment'= ($vm | Get-Annotation)[1].value;  
           #'Project'= ($vm | Get-Annotation)[2].value;  
           #'Role'= ($vm | Get-Annotation)[3].value;  
           }  
     $obj = New-Object -TypeName PSObject -Property $Props  
     Write-Output $obj | select-object -Property 'VMName', 'IP Address', 'Domain Name', 'Real-OS', 'vCPU', 'RAM(GB)', 'Total-HDD(GB)' ,'HDDs(GB)', 'Datastore', 'Partition/Size', 'Hardware Version', 'PowerState', 'Setting-OS', 'EsxiHost', 'vCenter Server', 'Folder', 'MacAddress', 'VMX', 'VMDK', 'VMTools Status', 'VMTools Version', 'VMTools Version Status', 'VMTools Running Status', 'SnapShots', 'DataCenter', 'vNic', 'PortGroup', 'RDMs' # 'Folder', 'Department', 'Environment' 'Environment'  
   }  
 }  
 Get-VMinventory 

 $obj | Sort VMName | Export-Csv -Path "c:\vminventory.csv"

Sunday, May 27, 2018

VMware script to get CPU core details.

Save the given file in machine and give extension ".ps1"

$myCol = @()
Foreach ($cluster in Get-Cluster)
    {
        Foreach($vmhost in ($cluster | Get-VMHost))
        {
            Foreach($vm in (Get-VM -Location $vmhost)){
                $VMView = $vm | Get-View
                $VMSummary = "" | Select ClusterName,HostName,VMName,VMSockets,VMCores,CPUSockets,CPUCores
                $VMSummary.ClusterName = $cluster.Name
                $VMSummary.HostName = $vmhost.Name
                $VMSummary.VMName = $vm.Name
                $VMSummary.VMSockets = $VMView.Config.Hardware.NumCpu
                $VMSummary.VMCores = $VMView.Config.Hardware.NumCoresPerSocket
                $VMSummary.CPUSockets = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuPackages
                $VMSummary.CPUCores = $vmhost.ExtensionData.Hardware.CpuInfo.NumCpuCores
                $myCol += $VMSummary
            }
        }
    }
$myCol | Export-csv reports.csv

Now connect vcenter using vmware powercli and execute the script.


Another method to get done this is follow below mentioned file save and execute the same to get the data.


Don't forget to change the given lines with your scenario.



  • $vcenter = vc01.vcdx56.com
  • $vcenteruser = vcdx56\magnus”
  • $vcenterpw = “not secret”
  • $reportdir = c:\vSpherereport
  • $filename = c:\vSphere$date.html
  • $basefile = c:\vSpherereportCPU-oversubscription.html

 # The script will calculate the ESXi host CPU core to VM vCPU oversubscription and create a HTML report

#
# Version 1.0 Magnus Andersson RTS
#————————————————
# Start of script parameters section
#
# vCenter Server configuration
$vcenter = “vcenter-ip-address“
$vcenteruser = “Administrator@vsphere.local“
$vcenterpw = "password"
#
$date=get-date -uformat %Y-%m-%d
#
# Define report directory
$reportdir = "c:\temp\vSpherereport"
#
# Define file name
$filename = "c:\temp\vSphere$date.html"
#
# Define base file
$basefile = "c:\temp\vSpherereportCPU-oversubscription.html"
#
# End of script parameter section
#—————————————— #
#
# Connect to vCenter Server
connect-viserver $vcenter -User $vcenteruser -Password $vcenterpw
#
function Get-Cluster-CPUMem {
$table = @()
foreach($clust in (get-cluster | Sort-Object Name)) {
$esx = $clust | Get-VMHost
$clu = "" | select Cluster, "ESXi host num CPU core", "VM vCPU", "VM vCPU on", "Percent of vCPU on"
$vms = $clust | get-vm
$clu.Cluster = $clust.Name
$clu."ESXi host num CPU core" = ($clust | Get-vmhost | Measure-Object -Sum NumCPU).Sum
$clu."VM vCPU" = ($vms | Measure-Object -Sum NumCPU).Sum
$clu."VM vCPU on" = ($vms | ?{$_.PowerState -eq "PoweredOn"} | Measure-Object -Sum NumCPU).Sum
$clu."Percent of vCPU on" = "{0:P0}" -f ($clu."VM vCPU on" / $clu."ESXi host num CPU core")
$table += $clu
}
$clu = "" | select Cluster, "ESXi host num CPU core", "VM vCPU", "VM vCPU on", "Percent of vCPU on"
$clu.Cluster = "Total"
$clu."ESXi host num CPU core" = ($table | Measure-Object -property "ESXi host num CPU core" -sum).sum
$clu."VM vCPU" = ($table | Measure-Object -property "VM vCPU" -sum).sum
$clu."VM vCPU on" = ($table | Measure-Object -property "VM vCPU on" -sum).sum
$clu."Percent of vCPU on" = "{0:P0}" -f ($clu."VM vCPU on" / $clu."ESXi host num CPU core")
$table += $clu
$table
}
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 4px;border-style: solid;border-color: black;text-align:center;}"
$a = $a + "</style>"
Get-Cluster-CPUMem | ConvertTo-HTML -head $a -Title "CPU oversubscription report $date" | Out-File $filename
Remove-Item $basefile
Copy-Item $filename $basefile
if ($filename -like "*-01.*") {
Copy-Item $filename $reportdir
}
Remove-item $filename