Friday, June 4, 2021

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