This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Saturday, September 16, 2017

List all orphaned vmdk on all datastores in all VC's at a time by using script

Saturday, September 16, 2017 0
Use the below script to achieve :

# Just paste the code in text file and rename with .ps1
# Purpose : List all orphaned vmdk on all datastores in all VC's
#Here fwvc950","fwvc951","fwvc952","flsan01 are my vcentrer

$arrayVC = "fwvc950","fwvc951","fwvc952","flsan01"
$OutputFile = "C:\OrphanedVMDK.txt"

Foreach ($strVC in $arrayVC)

{
    Connect-VIServer $strVC
    $arrUsedDisks = Get-VM | Get-HardDisk | %{$_.filename}
    $arrDS = Get-Datastore
    Foreach ($strDatastore in $arrDS)
    {
       $strDatastoreName = $strDatastore.name
       Write-Host $strDatastoreName
       $ds = Get-Datastore -Name $strDatastoreName | %{Get-View $_.Id}
       $fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
       $fileQueryFlags.FileSize = $true
       $fileQueryFlags.FileType = $true
       $fileQueryFlags.Modification = $true
       $searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
       $searchSpec.details = $fileQueryFlags
       $searchSpec.sortFoldersFirst = $true
       $dsBrowser = Get-View $ds.browser
       $rootPath = "["+$ds.summary.Name+"]"
       $searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
       $myCol = @()
       foreach ($folder in $searchResult)
       {
          foreach ($fileResult in $folder.File)
          {
             $file = "" | select Name, FullPath   

             $file.Name = $fileResult.Path

             $strFilename = $file.Name

             IF ($strFilename)

             {

             IF ($strFilename.Contains(".vmdk"))

             {

             IF (!$strFilename.Contains("-flat.vmdk"))

             {

             IF (!$strFilename.Contains("delta.vmdk"))         

             {

                $strCheckfile = "*"+$file.Name+"*"

             IF ($arrUsedDisks -Like $strCheckfile){}

             ELSE

             {            

             $strOutput = $strDatastoreName + " Orphaned VMDK Found: " + $strFilename

             $strOutput | Out-File $Outputfile -width 150 -Append

             }            

             }

             }         

             }

             }

          }

       }      

   }  

}

Friday, September 15, 2017

List the types of DB supported by openldap?

Friday, September 15, 2017 0

Below list of DBs are supported by openldap

bdb

Berkeley DB instance definition. This is the recommended database back-end type. It uses the Sleepycat Berkeley DB to store data.


ldbm

LDAP DBM type. Easy to configure, but not as durable as the bdb database back-end type. It also uses Berkeley DB, GNU DBM, and MDBM to store data.


sql

Uses a SQL database back-end to store data.


ldap

Used as a proxy to forward incoming requests to another LDAP server.

meta

Metadirectory database back-end. It is an improvement on the LDAP-type back-end. It performs LDAP proxying with respect to a set of remote LDAP servers.

monitor

Stores information about the status of the slapd daemon.

null

Operations to this database type succeed, but do nothing. This is the equivalent of sending stuff to /dev/null in Linux/UNIX.

passwd

Uses the system’s plain-text /etc/passwd file to serve user account information.

tcl

An experimental back-end that uses a Tcl interpreter that is embedded directly into slapd.

perl

Uses a Perl interpreter that is embedded directly into slapd.

Rescan All HBA of all ESXI in a simple way.

Friday, September 15, 2017 0

Rescan All HBA of all ESXI in a simple way.

For a Specific Cluster:

get-cluster -name “MY CLUSTER” | get-vmhost | Get-VMHostStorage -RescanAllHBA

All Hosts in VC:

get-vmhost | Get-VMHostStorage -RescanAllHBA

Thursday, September 14, 2017

Repairing Linux ext2 or ext3 FS

Thursday, September 14, 2017 0

Repairing Linux ext2 or ext3 file system

1) File system must be unmounted, you cannot repair it while it is running. Take system down to runlevel one (make sure you run all command as root user):# init 1

2)Unmount file system, for example if it is /home (/dev/sda3) file system then type command

# umount /home OR# umount /dev/sda3


3) Now run fsck on the partition: 

# fsck /dev/sda3

However be sure to specify the file system type using -t option. Recenly one of our sys admin run the command on ext3 file system w/o specifying file system. Result was more corruption as fsck by default assumes ext2 file system.

 # fsck -t ext3 /dev/sda3
OR# fsck.ext3 /dev/sda3


Tip if you don't know your file system type then typing mount command will display file system type.

fsck will check the file system and ask which problems should be fixed or corrected. If you don't wanna type y every time then you can use pass -y option to fsck


# fsck -y /dev/sda3

Please not if any files are recovered then they are placed in /home/lost+found directory by fsck command.

4) Once fsck finished, remount the file system:

# mount /home

5) Go to multiuser mode# init 3

Read man page of fsck for more.

How tcpdump command is used to find out the network switch information which is connected to the physical server?

Thursday, September 14, 2017 0
Run the below tcpdump command on physical server.

[root@testserver001 ~]# tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
tcpdump: WARNING: eth0: no IPv4 address assigned
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 1500 bytes
05:51:39.526913 CDPv2, ttl: 180s, checksum: 692 (unverified), length 434
        Device-ID (0x01), length: 21 bytes: 'TEST01.switch.com'
        Version String (0x05), length: 295 bytes:
          Cisco Internetwork Operating System Software
          IOS (tm) s72033_rp Software (s72033_rp-ADVIPSERVICESK9_WAN-M), Version 12.2(18)SXF17a, RELEASE SOFTWARE (fc1)
          Technical Support: http://www.cisco.com/techsupport
          Copyright (c) 1986-2010 by cisco Systems, Inc.
          Compiled Tue 02-Mar-10 01:50 by tinhuang
        Platform (0x06), length: 16 bytes: 'cisco WS-C6506-E'
        Address (0x02), length: 13 bytes: IPv4 (1) 159.166.128.131
        Port-ID (0x03), length: 16 bytes: 'FastEthernet3/12'
        Capability (0x04), length: 4 bytes: (0x00000029): Router, L2 Switch, IGMP snooping
        VTP Management Domain (0x09), length: 0 byte: ''
1 packets captured
3 packets received by filter
0 packets dropped by kernel

Powershell script to list the Virtual Machines in SCVMM

Thursday, September 14, 2017 0

Windows PowerShell (SCVMM)

SCVMM One-liner command 1:   Outputs the VMName, VM Configuration File path, VHDCount, VHD Location, VHDSize, MaxVHDSize, Cluster for all VMs managed by the SCVMM server connected by PowerShell (in a single line)

$report = @(); $vms = get-vm; foreach ($vm in $vms){foreach ($vhd in $vm.VirtualHardDisks){$maxvhdsize = [math]::Round($vhd.MaximumSize/1024/1024/1024,1); $vhdsize = [math]::Round($vhd.Size/1024/1024/1024,1); $row = "" | select VMName, VMCPath, VHDCount, VHDLocation, VHDSize, MaxVHDSize, VMCluster; $row.VMName = $vm.Name; $row.VMCPath = $vm.VMCPath; $row.VHDCount = $vm.VirtualHardDisks.Count; $row.VHDLocation = $vhd.Location; $row.VHDSize = $vhdSize; $row.MaxVHDSIze = $MaxVHDSize; $row.VMCluster = $vm.VMHost.HostCluster.Name; $report += $row;};};$report | export-csv C:\Temp\Hyper-V-VMs.csv -NoTypeInformation


 

Brief Introduction about Annotation/ custom attributes in Vmware

Thursday, September 14, 2017 0

What are custom attributes?

Custom Attributes are attributes that a administrator can define for all Virtual Machines and Hosts in vCenter. The attributes are then displayed in the “Annotations” box for each VM. The custom attributes are also displayed alongside the VM Name, Status, State, CPU Usage, etc, when listing virtual machines in the Datacenter, cluster, host, and resource pool views.

Why use them?

Daily, we receive lots of clone requests for VMs. Clones are very good for application development and application troubleshooting. When an application on a VM goes pear shaped, the application vendor may request a clone for a system. They can then work on the clone system to try and fix some issues while the production system (if not broken completely) may in some cases still remain partially available to the end users. Once they are confident that they have resolved the issue, they can then implement the fix in the production environment.

This is all good and well, but here’s the problem. Clones are a drain on your resources. As administrator, you should be very careful to simply hand out clones as the requests come in. Virtual Machine clones can create a nightmare for administrators as they use huge amounts of additional disk space. Some of the clones we have today are in excess of 420GB. When creating clones, we need to make sure that the following information is recorded somewhere in vCenter:

·         Who requested the clone;

·         The requestor’s contact number/email address

·         The date that the clone was made;

·         The size of the clone on disk (all vDisk sizes combined + the amount of RAM  assigned to the VM);

·         Does it need to be backed up (Yes / No);

·         Reason for the clone;


Specifying your own Custom Attributes

Creating custom attributes is very simple. In the VI (or vSphere) client on the menu bar, click “Administration” >> “Custom Attributes...”

You’ll now be presented with the Custom Attributes dialog: You can file them b editing them manually once created.


Image

Getting ESXi Network driver firmware details by using Script.

Thursday, September 14, 2017 0
Find the script as follows.

$ExportFilePath = "C:\Users\user\Desktop\esxi.txt"
$PuttyUser = "root"
$PuttyPwd = "w2k8the$"
$HostNic = "vmnic0,vmnic1"
$Plink = "C:\Users\user\Desktop\plink.exe"
$PlinkOptions = " -v -batch -pw $PuttyPwd"
$RCommand = '"' + "ethtool -i " + $HostNic + '"'
$ESXHosts = Get-VMHost | where {$_.Model -match "ProLiant BL*"} | Sort Name
$Report = @()
ForEach ($ESXHost in $ESXHosts) {
        $Message = ""
        $HostInfo = {} | Select HostName,ESXVersion,Cluster,pNic,DriverName,DriverVersion,DriverFirmware
        $HostInfo.HostName = $ESXHost.Name
        $HostInfo.ESXVersion = $ESXHost.Version
        $HostInfo.Cluster = (Get-Cluster -VMHost $ESXHost.Name).Name
        $HostInfo.pNic = $HostNic
        Write-Host "Connecting to: " $ESXHost.Name -ForegroundColor Green
        $Command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $rcommand
        $Message = Invoke-Expression -command $command
        $HostInfo.DriverName = ($Message[0] -split"driver:")[1]
        $HostInfo.DriverVersion = ($Message[1] -split"version:")[1]
        $HostInfo.DriverFirmware = ($Message[2] -split"firmware-version:")[1]
        $Report += $HostInfo
}

$Report = $Report | Sort-Object HostName
IF ($Report -ne "") {
$Report | Export-Csv $ExportFilePath -NoTypeInformation
}
Invoke-Item $ExportFilePath