Tuesday, June 15, 2021

Powershell script to collect OS details

Powershell script to collect OS details

##################################################
$ipaddress=Get-Content -Path C:\ry\ansible\ip.txt
#$ErrorActionPreference='silentlycontinue'
$results = @()

ForEach ($i in $ipaddress)
 {
$sess = New-PSSession -ComputerName $i
$osname=Invoke-Command -Session $sess -ScriptBlock {(gwmi win32_operatingsystem).caption}
$osbit=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).OSArchitecture}
$hostname=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).CSName}
$hItemDetails=[pscustomobject]@{
Hostname=$hostname
OS_Name=$osname
OS_bit=$osbit
}
$results +=$hItemDetails
}

$results | Export-Csv C:\ry\ansible\machinenames.csv

#############################################################

Monday, June 14, 2021

Powershell Ping report status script

Ping report status script

$result= @()
$names = Get-Content "c:\ip2.txt"
foreach ($name in $names){
  if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
   $Output= "up"
#   Write-Host "up" -ForegroundColor Green
  }
  else{
    $Output= "down"
#    Write-Host "down" -ForegroundColor Red
  }
$hItemDetails=[pscustomobject]@{
IP_address=$name
Status=$Output
}
$result +=$hItemDetails
}
$result | Export-Csv "c:\result2.csv"

Sunday, June 13, 2021

Ansible playbook to delete selected VMs from file.

Ansible playbook to delete selected VMs from file.

####################### delete selected VMs#######################


---
- name: Delete VMs from Vcenter
  hosts: localhost
  gather_facts: no
  vars:
    hostname: 192.168.0.x
    username: administrator@vsphere.local
    password: abcd@1234
  tasks:
  - name: Delete Vms
    vmware_guest:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      validate_certs: False
      name: "{{ item }}"
      state: absent
      wait_for_ip_address: no
    delegate_to: localhost
    with_lines: cat vmname.txt

Powershell script to disable/ enable vmwaretool with report status.

Powershell script to disable/ enable vmwaretool with report status.

#####################To Disable ###########################
$ErrorActionPreference='silentlycontinue'
Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}
$vmt=Get-VM|Get-View | select name,@{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } } |Sort Name
$results +=$vmt
$results | Export-Csv C:\ry\ansible\vmtoolstatus.csv

##########################To Enable####################################

$ErrorActionPreference='silentlycontinue'
Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}
$vmt=Get-VM|Get-View | select name,@{N='ToolsUpgradePolicy';E={$_.Config.Tools.ToolsUpgradePolicy } } |Sort Name
$results +=$vmt
$results | Export-Csv C:\ry\ansible\vmtoolstatus.csv

Saturday, June 12, 2021

Powershell script to collect hostname from ipaddress V2

Powershell script to collect hostname from ipaddress

##################################################

$ipaddress=Get-Content -Path C:\ry\ansible\ip2.txt
$ErrorActionPreference='silentlycontinue'
$results = @()

ForEach ($i in $ipaddress)
 {
  
$o=new-object psobject
$o | Add-Member -MemberType NoteProperty -Name hostname -Value ([System.Net.Dns]::GetHostByAddress($i).HostName) | select 

-ExpandProperty hostname
$f=$o | select -ExpandProperty hostname
$hItemDetails=[pscustomobject]@{
IP_address=$i
Hostname=$f
}
$results +=$hItemDetails
}

$results | Export-Csv C:\ry\ansible\machinenames.csv

#############################################################

Ansible playbook to delete multiple vms

Ansible playbook to delete multiple vms

---
- name: Delete VMs from Vcenter
  hosts: localhost
  gather_facts: no
  vars:
    hostname: vcenter_ip
    username: vcenter_user
    password: vcenter_password
  tasks:
  - name: Delete Vms
    vmware_guest:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      validate_certs: False
      name: "{{ item }}"
      state: absent
      wait_for_ip_address: no
    delegate_to: localhost
    with_items:
    - testvm2
    - testvm_3

Friday, June 11, 2021

Powershell script to collect gateway ip of remote window system

Powershell script to collect gateway ip of remote window system

#############################################################

$ipaddress=Get-Content -Path C:\ry\ansible\ip.txt

$results = @()

ForEach ($i in $ipaddress)
 {
$sess = New-PSSession -ComputerName $i
$o=Invoke-Command -Session $sess -ScriptBlock {hostname}
$g=Invoke-Command -Session $sess -ScriptBlock {Get-NetIPConfiguration |Select -ExpandProperty IPv4DefaultGateway | select -ExpandProperty NextHop}
$hItemDetails=[pscustomobject]@{
Hostname=$o
Gateway=$g
}
$results +=$hItemDetails
}

$results | Export-Csv C:\ry\ansible\machinenames.csv

##############################################################

Powershell script to collect hostname from ipaddress

Powershell script to collect hostname from ipaddress

####################################################
$ipaddress=Get-Content -Path C:\ry\ansible\ip.txt

$results = @()

ForEach ($i in $ipaddress)
 {
  
$o=new-object psobject

$o | Add-Member -MemberType NoteProperty -Name hostname -Value ([System.Net.Dns]::GetHostByAddress($i).HostName)
$results +=$o
}

$results | Select-Object -Property hostname | Export-Csv C:\ry\ansible\machinenames.csv
#####################################################

Thursday, June 10, 2021

vmware tool auto update enable disable powershell code

############ To disable auto update vmware tool on selected vms##############

$srcvms = Get-Content c:\ry\ansible\vmname.txt
$vms = get-vm $srcvms
Foreach ($v in ($vms)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}


############ To enable auto update vmware tool on selected vms##############

$srcvms = Get-Content c:\ry\ansible\vmname.txt
$vms = get-vm $srcvms
Foreach ($v in ($vms)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}



############ To disable auto update vmware tool on all vms in vcenter##############


Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}


############ To enableauto update vmware tool on all vms in vcenter##############


Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}

Wednesday, June 9, 2021

SAN switch latency issue

 



Major issue on this error, disable port immediately if getting below error.

2021/06/08-13:56:17, [AN-1003], 1281572, SLOT 6 | FID 128, WARNING, switchname1, Latency bottleneck at slot 9, port 11. 10.33 percent of last 300 seconds were affected. Avg. time b/w transmits 1.0000 us.

2021/07/20-21:06:38, [AN-1010], 11564, SLOT 5 | FID 128, WARNING, backboneswitch, Severe latency bottleneck detected at slot 1 port 23.



investigate:

2021/06/08-14:40:22, [AN-1010], 1124481, SLOT 6 | FID 128, WARNING, switchname1, Severe latency bottleneck detected at slot 10 port 0.


investigate:

2021/06/09-11:54:34, [AN-1004], 1124531, SLOT 6 | FID 128, WARNING, switchname1, Slot 9, port 22 is a congestion bottleneck. 54.33 percent of last 300 seconds were affected by this condition.


check above logs by below command :

errdump |grep -i latency

errdump |grep -i bottleneck

errdump |grep -i congestion


check error on ports:

porterrshow (check crc, disc c3 errors)

check port flapping :

fabriclog -s








Tuesday, June 8, 2021

HP C7000 blade

 HP C7000 blade mazenine card configuration  

server mazenine 1, brocade 3-4

server mazenine 2, brocade 5-6

server mazenine 3, brocade 7-8

To collect naa id on linux

 


to collect naa id on linux


https://www.thegeekdiary.com/how-to-identifymatch-lun-presented-from-san-with-underlying-os-disk/


To get WWID of LUN you can use the /dev/disk/by-id/ file:


# ls -la /dev/disk/by-id/

scsi-3600508b400105e210000900000490000 -> ../../dm-1

Now its easier to understand that dm-1 has WWID 3600508b400105e210000900000490000


Saturday, June 5, 2021

Use of register and debug in Ansible

Use of register and debug in Ansible

---
- hosts: win
  tasks:
  - name: System date
    win_command: ipconfig
    register: ipconfig
  - debug: var=ipconfig.stdout_lines

Ansible playbook to add a line in a file

Ansible playbook to add a line in a file

---
  - hosts: node1
    tasks:
    - name: create file
      file:
        path: /home/ansible/hostname.conf
        state: touch
    - name:
      lineinfile:
        dest: /home/ansible/hostname.conf
        line: Hostname={{ ansible_hostname }}
        state: present

Ansible Handler use



---
- hosts: node1
  become: yes
  become_method: sudo
  tasks:
    - name: copy demo.example.conf configuration template
      copy:
        src: /etc/ansible/playbook/when.yml
        dest: /etc/tmp/when.yml
      notify:
        - stop_httpd
  handlers:
    - name: stop_httpd
      service:
        name: httpd
        state: stopped

use windows facts in ansible

check available facts for that host 

ansible -m setup hostname

---
- hosts: win
  tasks:
    - name: Get custom facts
      debug:
      msg: The custom fact is {{ansible_local.date_time}}

Friday, June 4, 2021

To enable kerberos authentication for ansible.

for kerberos
yum install python3-devel
yum install krb5-workstation
yum install krb5-devel
yum install krb5-libs
pip install kerberos
pip3 install pywinrm[kerberos]


edit below info in /etc/krb5.conf file then run kinit Administrator@AREA51.COM and kinit -S HOST/WIN-DQTK4K8NQ55.AREA51.COM

# To opt out of the system crypto-policies configuration of krb5, remove the
# symlink at /etc/krb5.conf.d/crypto-policies which will not be recreated.
includedir /etc/krb5.conf.d/

[logging]
    default = FILE:/var/log/krb5libs.log
    kdc = FILE:/var/log/krb5kdc.log
    admin_server = FILE:/var/log/kadmind.log

[libdefaults]
    dns_lookup_realm = false
    ticket_lifetime = 24h
    renew_lifetime = 7d
    forwardable = true
    rdns = false
    pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt
    spake_preauth_groups = edwards25519
    default_realm = AREA51.COM
    default_ccache_name = KEYRING:persistent:%{uid}
    default_tgs_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
    default_tkt_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
    permitted_enctypes = aes256-cts-hmac-sha1-96 rc4-hmac des-cbc-crc des-cbc-md5
[realms]
#kdc = AREA51.COM
 AREA51.COM = {
     kdc = area51.com:88
     admin_server = area51.com:749
 }

[domain_realm]
 .area51.com = AREA51.COM
 area51.com = AREA51.COM

https://docs.ansible.com/ansible-tower/3.1.3/html/administration/kerberos_auth.html
https://access.redhat.com/solutions/4911041
for domain controller relation issue
https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/verify-srv-dns-records-have-been-created

Configure VMware.PowerCLI on powershell

 


Install-Module -Name VMware.PowerCLI

Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction warn

To enable virtualization support on VM

 

To enable virtualization support on VM

add below mentioned line in vm vmx file 


vhv.enable = "TRUE"

####################################

evcCompatibilityMode = "FALSE"

monitor.phys_bits_used = "40"

vmotion.checkpointFBSize = "4194304"

cleanShutdown = "TRUE"

softPowerOff = "FALSE"

tools.syncTime = "FALSE"

vhv.enable = "TRUE"

ide1:0.startConnected = "FALSE"

ide1:0.allowGuestConnectionControl = "TRUE"

config.readOnly = "FALSE"

ethernet0.virtualDev = "vmxnet3"

ethernet0.networkName = "VM Network"

ethernet0.addressType = "generated"

ethernet0.uptCompatibility = "TRUE"

ethernet0.present = "TRUE"

ethernet0.pciSlotNumber = "160"

ethernet0.generatedAddress = "00:0c:29:de:59:84"

ethernet0.generatedAddressOffset = "0"

ethernet1.pciSlotNumber = "192"

ethernet1.virtualDev = "vmxnet3"

ethernet1.networkName = "VM Network"

ethernet1.addressType = "generated"

ethernet1.uptCompatibility = "true"

ethernet1.present = "TRUE"

ethernet1.generatedAddress = "00:0c:29:de:59:8e"

ethernet1.generatedAddressOffset = "10"

extendedConfigFile = "ESXi6.7.vmxf"

vhv.enable = "TRUE"

Ansible Playbook to create or remove windows directory

Ansible Playbook to create or remove windows directory

---
- hosts: win
  tasks:
    - name: create directory
      win_file:
        path: 'c:\ry\ansibletest'
        state: directory

---
- hosts: win
  tasks:
    - name: create directory
      win_file:
        path: 'c:\ry\ansibletest'
        state: absent

To enable Sudo access on particular without password.

 edit visudo file on ubuntu and centos

add this line to get sudo access on ansible account without password

## Allow root to run any commands anywhere

root    ALL=(ALL)       ALL

ansible ALL=(ALL)       NOPASSWD: ALL


now for sudo access need to run command with -b 

ansible node -b -a "reboot"


ansible node* -m setup to check node info

To enable key for connect password less node from ansible.

now will generate key for password less authentication from ansible controller to node1
create ansible user on node1 
useradd ansible 

sudo ansible
cd ~
ls -l
ls -la
mkdir .ssh/
vi .ssh/authorized_keys

now goto contoller
ssh-keygen
cat /root/.ssh/id_rsa.pub
copy the code key and go back to node1 
paste there and save file
chmod -R 700 .ssh/ on node1 

not try to connect node1 from controller. it should connect without password.

now edit hosts files under /etc/ansible/hosts on cotroller machine

add the entry of host ip

also edit the /etc/ansible/ansible.cfg file for remote_user= ansible

now try ansible all -m ping 

ansible all -a "uptime"

Command to set the Linux hostname.

 

hostnamectl set-hostname area51-controller


exec bash

To Enable ethernet and make persistent in CentOS

 CENTOS :

ip r to check ip address

sudo ip addr add 10.102.66.200/24 dev enp0s25

nmcli to check ethernet 

nmcli dev connect ethernetname to enable port

ip link set dev enp0s25 up

Open the configuration file for your network interface.

vi /etc/sysconfig/network-scripts/ifcfg-eth0

Add the following settings to the file:

DEVICE=enp3s0

ONBOOT=yes

IPADDR=192.168.1.10

NETMASK=255.255.255.0

GATEWAY=192.168.1.1


To enable winRM

To enable winRM

Source: https://support.infrasightlabs.com/help-pages/how-to-enable-winrm-on-windows-servers-clients/#:~:text=In%20the%20Group%20Policy%20Management,configuration%20of%20listeners%E2%80%9D%20policy%20setting.

test winRM is working or not.
PS C:\Users\ctdh4743> Test-WSMan


wsmid           : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd
ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
ProductVendor   : Microsoft Corporation
ProductVersion  : OS: 0.0.0 SP: 0.0 Stack: 3.0

follow below 
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\WINDOWS\system32> winrm enumerate winrm/config/Listner
WSManFault
    Message
        ProviderFault
            WSManFault
                Message = The WS-Management service cannot process the request. The resource URI does not support the Enumerate operation.

Error number:  -2144108495 0x80338031
The WS-Management service cannot process the request because the WS-Addressing Action URI in the request is not compatible with the resource.
PS C:\WINDOWS\system32> winrm emunerate winrm/config/Listner
Error: Unknown operation name: 'emunerate'
PS C:\WINDOWS\system32> winrm enumerate winrm/config/Listner
WSManFault
    Message
        ProviderFault
            WSManFault
                Message = The WS-Management service cannot process the request. The resource URI does not support the Enumerate operation.

Error number:  -2144108495 0x80338031
The WS-Management service cannot process the request because the WS-Addressing Action URI in the request is not compatible with the resource.
PS C:\WINDOWS\system32> $url = https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
>>
>>
>> ^C
PS C:\WINDOWS\system32> $url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> $file = "$env:temp\ConfigureRemotingForAnsible.ps1"
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> (New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
PS C:\WINDOWS\system32> powershell.exe -ExecutionPolicy ByPass -File $file
Self-signed SSL certificate generated; thumbprint: 2239709A676E19C945F2A6CDA58D93D01F465D06


wxf                 : http://schemas.xmlsoap.org/ws/2004/09/transfer
a                   : http://schemas.xmlsoap.org/ws/2004/08/addressing
w                   : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd
lang                : en-US
Address             : http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
ReferenceParameters : ReferenceParameters

Ok.



PS C:\WINDOWS\system32> winrm enumerate winrm/config/Listner
WSManFault
    Message
        ProviderFault
            WSManFault
                Message = The WS-Management service cannot process the request. The resource URI does not support the Enumerate operation.

Error number:  -2144108495 0x80338031
The WS-Management service cannot process the request because the WS-Addressing Action URI in the request is not compatible with the resource.
PS C:\WINDOWS\system32> winrm enumerate winrm/config/Listener
Listener
    Address = *
    Transport = HTTP
    Port = 5985
    Hostname
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint
    ListeningOn = 127.0.0.1, 192.168.29.167, 192.168.29.226, ::1

Listener
    Address = *
    Transport = HTTPS
    Port = 5986
    Hostname = EQ-EQ6283300
    Enabled = true
    URLPrefix = wsman
    CertificateThumbprint = 2239709A676E19C945F2A6CDA58D93D01F465D06
    ListeningOn = 127.0.0.1, 192.168.29.167, 192.168.29.226, ::1















Get-WmiObject -Class Win32_ComputerSystem -ComputerName 192.168.100.100 -Credential domain\mywmiuser

VM disk info powershell script

VM disk info powershell script

$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
  ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) { 
    ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
      ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
        "" | Select-Object -Property @{N="VM";E={$VM.Name}},
          @{N="Datacenter";E={$Datacenter.name}},
          @{N="Cluster";E={$Cluster.Name}},
          @{N="Hard Disk";E={$HardDisk.Name}},
          @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
          @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
          @{N="VMDKpath";E={$HardDisk.FileName}},
  @{N="Storage Format";E={$HardDisk.StorageFormat}},
          @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}}
      }
    }
  }
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "VmInfo.csv"

#############################

# Get data about vmdk and format
# Niklas Ã…kerlund / RTS

$VMs = Get-VM *
$Data = @()

 foreach ($VM in $VMs){
$VMDKs = $VM | get-HardDisk
foreach ($VMDK in $VMDKs) {
if ($VMDK -ne $null){
$CapacityGB = $VMDK.CapacityKB/1024/1024
$CapacityGB = [int]$CapacityGB
$into = New-Object PSObject
Add-Member -InputObject $into -MemberType NoteProperty -Name VMname $VM.Name
Add-Member -InputObject $into -MemberType NoteProperty -Name Datastore $VMDK.FileName.Split(']')[0].TrimStart('[')
Add-Member -InputObject $into -MemberType NoteProperty -Name VMDK $VMDK.FileName.Split(']')[1].TrimStart('[')
Add-Member -InputObject $into -MemberType NoteProperty -Name StorageFormat $VMDK.StorageFormat
Add-Member -InputObject $into -MemberType NoteProperty -Name CapacityGB $CapacityGB
$Data += $into
}
}

}
$Data | Sort-Object VMname,Datastore,VMDK | Export-Csv -Path C:\iso\VM-VMDKs.csv -NoTypeInformation

LUN report – datastore, RDM and node visibility

param($clusName,$csvName=("C:\Temp\" + $clusName + "-LUN.csv"))
 
$rndNum = Get-Random -Maximum 99999
 
$LunInfoDef = @"
public string ClusterName;
public string CanonicalName;
public string UsedBy;
public string SizeMB;
"@
$LunInfoDef = "public struct LunInfo" + $rndNum + "{`n" + $LunInfoDef
 
$esxServers = Get-Cluster | Get-VMHost | Sort-Object -Property Name
$esxServers | %{
$LunInfoDef += ("`n`tpublic string " + ($_.Name.Split(".")[0]) + ";")
}
$LunInfoDef += "`n}"

$scsiTab = @{}
$esxServers | %{
$esxImpl = $_
 

$esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{
 
$key = $esxImpl.Name.Split(".")[0] + "-" + $_.CanonicalName.Split(".")[1]
if(!$scsiTab.ContainsKey($key)){
 
$scsiTab[$key] = $_.CanonicalName,"",$_.CapacityMB
}
}
# Get the VMFS datastores
$esxImpl | Get-Datastore | where {$_.Type -eq "VMFS"} | Get-View | %{
$dsName = $_.Name
$_.Info.Vmfs.Extent | %{
$key = $esxImpl.Name.Split(".")[0] + "-" + $_.DiskName.Split(".")[1]
$scsiTab[$key] = $scsiTab[$key][0], $dsName, $scsiTab[$key][2]
}
}
}
# Get the RDM disks
Get-Cluster | Get-VM | Get-View | %{
$vm = $_
$vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{
if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){
$disk = $_.Backing.LunUuid.Substring(10,32)
$key = (Get-View $vm.Runtime.Host).Name.Split(".")[0] + "-" + $disk
$scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label
}
}
}
Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
 
 
# Get SCSI LUNs
$scsiTab.GetEnumerator() | Group-Object -Property {$_.Key.Split("-")[1]} | %{
$lun = New-Object ("LunInfo" + $rndNum)
$lun.ClusterName = $clusName
$_.Group | %{
$esxName = $_.Key.Split("-")[0]
$lun.$esxName = "ok"
if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}
if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}
if(!$lun.SizeMB){$lun.SizeMB = $_.Value[2]}
 
}
$lun
}

Export-Csv $csvName -NoTypeInformation -UseCulture
Invoke-Item $csvName

VM clone create powershell script

 

#$srcvms = get-vm -location "LAB" | select -expandproperty Name (for complete cluster or DC)

$srcvms = Get-Content c:\ry\ansible\vmname.txt

Foreach ($srcvm in $srcvms) {


#$srvcvms_strip = $srcvm -replace "LAB_"


new-vm -name "Clone_$srcvm" -vm $srcvm -vmhost esx01 -datastore "datastore11" -DiskStorageFormat Thin


}

#####################

To run cloning on all VMs at a time use below.

########################

#$srcvms = get-vm -location "LAB" | select -expandproperty Name (for complete cluster or DC)

$srcvms = Get-Content c:\ry\ansible\vmname.txt

Foreach ($srcvm in $srcvms) {


#$srvcvms_strip = $srcvm -replace "LAB_"


new-vm -name "Clone_$srcvm" -vm $srcvm -vmhost esx01 -datastore "datastore11" -DiskStorageFormat Thin -RunAsync


}



vol clone and ndmpcopy

 

vol clone create smtp_attachment_T2_001_sv_restore -s none -b source_smtp_attachment_T2_001_sv  snapshotname_01


run below where you want to restore file.

 ndmpcopy -sa root:password sourcebackupfiler:/vol/smtp_attachment_T2_001_sv_restore/qt01/tc/transfertFTP/numTransmission.xml /vol/test01/restore