22
Déc
Comment afficher les informations des disques VMware d’une Machine en PowerCli?
Pour cela, j’ai récupéré une petite Commande posté par LucD sur le forum communities.vmware.com
Cela vous permet d’avoir toutes les information concernant les disques VMWare de votre machine virtuel (nom du volume, capacité, scsi, naa pour un RDM, vmdk, …)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
. . param( [Parameter (Mandatory = $true)] [String]$nomVm ) Get-VM -name $nomVm | Get-HardDisk | Select @{N='VM';E={$_.Parent.Name}}, Name,CapacityGB,FileName,@{N='Datastore';E={$_.FileName.Split(']')[0].TrimStart('[')}}, @{N='SCSIid';E={"{0}:{1}" -f (&{$script:ctrl = Get-ScsiController -HardDisk $_; $script:ctrl.ExtensionData.BusNumber}),$_.ExtensionData.UnitNumber}}, @{N='SCSI Shared';E={$script:ctrl.BusSharingMode}}, @{N='RDM';E={if($_.DiskType -match 'Physical'){$_.ScsiCanonicalName}}} | FT -AutoSize . |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
. VM Name CapacityGB Filename Datastore SCSI Shared RDM ------------------- -------------- ----------------- ---------------------------------------------------------------------------------- -------------------------- --------- ----------------- --------------------------------------- maVmdeTest Hard disk 1 80 [monDatastoreDeTest] maVmdeTest/maVmdeTest.vmdk monDatastoreDeTest 0:0 NoSharing maVmdeTest Hard disk 2 50 [monDatastoreDeTest] maVmdeTest/maVmdeTest_1.vmdk monDatastoreDeTest 0:1 NoSharing maVmdeTest Hard disk 3 0,50 [monDatastoreDeTest2] maVmdeTest/maVmdeTest.vmdk monDatastoreDeTest2 1:0 Physical naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx maVmdeTest Hard disk 4 400 [monDatastoreDeTest2] maVmdeTest/maVmdeTest_1.vmdk monDatastoreDeTest2 2:0 Physical naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx maVmdeTest Hard disk 5 200 [monDatastoreDeTest2] maVmdeTest/maVmdeTest_2.vmdk monDatastoreDeTest2 3:0 Physical naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx maVmdeTest Hard disk 6 200 [monDatastoreDeTest2] maVmdeTest/maVmdeTest_3.vmdk monDatastoreDeTest2 1:1 Physical naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx maVmdeTest Hard disk 7 400 [monDatastoreDeTest2] maVmdeTest/maVmdeTest_4.vmdk monDatastoreDeTest2 2:1 Physical naa.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx . |
Powershell VMware – Get Datastore Name et Canonicale Name
1 2 3 4 5 6 7 8 9 10 11 12 |
. PS D:\> Get-Datastore | <br>select Name,<br>@{N='CanonicalName';E={[string]::Join(",",$(($_.Extensiondata.Info.Vmfs.Extent.DiskName)))}} Name CanonicalName ---- ------------- monDatastore1 naa.624a1111111cd111111c4413fa00011111 monDatastore2 naa.624a2222226222222bac44cf00022222 monDatastore3 naa.624a3333326333333bac44cf00033333,naa.624a4444426444444bac44cf00044444 . |
Détail des infrastructures VMware auxquels nous sommes connecté ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
. Foreach($vc in $global:DefaultVIServers){ foreach($dc in Get-Datacenter -Server $vc){ Get-Cluster -Location $dc -Server $vc | Select @{N='VC';E={$vc.Name}},@{N='Datacenter';E={$dc.Name}},@{N='Cluster';E={$_.Name}},@{N='#ESXi';E={$_.ExtensionData.Host.Count}},@{N='#VM';E={(Get-View -Id $_.ExtensionData.Host).Vm.Count}} | Format-Table -AutoSize } } . |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
. VC Datacenter Cluster ESXi VM ------------ ----------------- ------------ --------- ------ vcenter1 PARIS clusterX 2 5 VC Datacenter Cluster ESXi VM ------------ ----------------- ------------ --------- ------ vcenter2 LILLE clusterY 2 13 VC Datacenter Cluster ESXi VM ------------ ----------------- ------------ --------- ------ vcenter3 MARSEILLES cluster1 4 180 vcenter3 MARSEILLES cluster2 6 200 vcenter3 MARSEILLES cluster3 6 200 vcenter3 MARSEILLES cluster4 2 60 vcenter3 MARSEILLES cluster5 2 60 . |
Qui a créé ces Snapshots ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
. #http://vstrong.info/2013/08/20/who-created-these-vm-snapshots/ . Foreach($vc in $global:DefaultVIServers){ foreach($dc in Get-Datacenter -Server $vc){ Get-Cluster -Location $dc -Server $vc | Select @{N='VC';E={$vc.Name}},@{N='Datacenter';E={$dc.Name}},@{N='Cluster';E={$_.Name}},@{N='#ESXi';E={$_.ExtensionData.Host.Count}},@{N='#VM';E={(Get-View -Id $_.ExtensionData.Host).Vm.Count}} | Format-Table -AutoSize } } . |
1 2 3 4 5 6 7 8 9 10 |
. VM: VM1. Snapshot 'SNAPSHOT_20170807' created on lundi 7 août 2017 13:31:26. This event is not in vCenter events database VM: VM2. Snapshot 'SNAPSHOT_2017-07-11' created on mardi 11 juillet 2017 11:48:50. This event is not in vCenter events database VM: VM3. Snapshot 'SNAPSHOT_20181211' created on mardi 11 décembre 2018 11:13:11 by monDomaine\mesIdentifiants. VM: VM4. Snapshot '2016-12-01 - Initail Snapshot- Power Off - A Garder' created on jeudi 1 décembre 2016 15:31:33. This event is not in vCenter events database VM: VM5. Snapshot 'SNAPSHOT_2015-09-24' created on jeudi 24 septembre 2015 13:30:01. This event is not in vCenter events database . |
Information Os, Tools et Hardware Vm
Il peut être intéressant dans certaines circonstances de récupérer en plus de l’Os de la VM des informations concernant les Tools et le hardware
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
. $report = @() get-cluster -name MonCluster| get-vm | %{ $row="" | select NAME,OS,VersionTools,NumVersionTools,versionHardware,NombreController,TypeController $row.Name = $_.Name $row.OS = $_.Guest.OSFullName $row.VersionTools = $_.Guest.ExtensionData.ToolsVersion $row.NumVersionTools= $_.Guest.ToolsVersion $row.versionHardware = $_.Version $row.NombreController = ($_ | Get-ScsiController).count $row.TypeController = [string]::Join(",",$(($_ | Get-ScsiController).type | Sort-Object | Get-Unique)) $report += $row } $report | FT . |
1 2 3 4 5 6 7 8 9 |
. MaVM1 Microsoft Windows Server 2008 R2 (64-bit) 10249 10.0.9 v11 1 VirtualLsiLogicSAS MaVM2 Microsoft Windows Server 2012 (64-bit) 10249 10.0.9 v11 1 ParaVirtual MaVM3 Microsoft Windows Server 2016 (64-bit) 10309 10.2.5 v11 2 ParaVirtual,VirtualLsiLogicSAS . |
Ouvrir ou Fermer sur le Firewall d’un ESXi le port du « Client SSH »
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
. # ---------------------------------------------------------------------------- # Activer ou Desactiver le Client SSH sur un ESXI # ---------------------------------------------------------------------------- # # activer Get-vmhost -name MonEsxi | Get-VMHostFirewallException -Name "SSH CLIENT" |Set-VMHostFirewallException -Enabled $true # # desactiver Get-vmhost -name MonEsxi | Get-VMHostFirewallException -Name "SSH CLIENT" |Set-VMHostFirewallException -Enabled $false # . |
Lister en PowerCli les répertoires Scratch Config
1 2 3 4 5 6 7 8 9 10 11 |
# ---------------------------------------------------------------------------- # Verification Repertoire Scratch Config # ---------------------------------------------------------------------------- get-cluster -name MonCluster| Get-VMHost | SELECT NAME, @{N=”Version”;E={$_.version}}, @{N=”Build”;E={$_.extensiondata.config.product.build}}, @{N=”ScratchConfig.CurrentScratchLocation”;E={$($_ | Get-AdvancedSetting -Name ScratchConfig.CurrentScratchLocation).Value}}, @{N=”ScratchConfig.ConfiguredScratchLocation”;E={$($_ | Get-AdvancedSetting -Name ScratchConfig.ConfiguredScratchLocation).Value}} | FT -AutoSize |
1 2 3 4 5 6 7 8 9 10 |
. Name Version Build ScratchConfig.CurrentScratchLocation ScratchConfig.ConfiguredScratchLocation MonEsxi1 6.7.0 11675023 /vmfs/volumes/5xxxx-bxxxx-8xxx-4xxxx /vmfs/volumes/5xxxx-bxxxx-8xxx-4xxxx MonEsxi2 6.7.0 11675023 /vmfs/volumes/5xxxx-bxxxx-dxxx-dxxxx /vmfs/volumes/5xxxx-dxxxx-dxxx-dxxxx . |
Vérification du Syslog
Syslog est-il activé sur mes ESXIs ?
1 2 3 |
. Get-Vmhost | select name, @{N=’Exception’;E={($_ | Get-VMHostFirewallException -Name syslog).name}},@{N=’Enabled’;E={($_ | Get-VMHostFirewallException -Name syslog).enabled}} | Format-Table -AutoSize . |
1 2 3 4 5 |
Name Exception Enabled monEsxi1 syslog True monEsxi2 syslog True monEsxi3 syslog True |
Verifier la configuration de Syslog sur mes ESXIs
1 2 3 4 5 |
. Get-VMHost | select name,@{N=’Log’;E={($_ | Get-AdvancedSetting -Name syslog.global.logHost).name}},@{N=’value’;E={($_ | Get-AdvancedSetting -Name syslog.global.logHost).value}} | Format-Table -AutoSize . |
1 2 3 4 5 |
Name Log value MonEsxi1 Syslog.global.logHost udp://monsyslog.monDomaine.fr:514 MonEsxi2 Syslog.global.logHost udp://monsyslog.monDomaine.fr:514 MonEsxi3 Syslog.global.logHost udp://monsyslog.monDomaine.fr:514 |
Redémarrer les Open-Vm-Tools
Commande à lancer sous RedHat (en root) :
1 2 3 4 5 |
. systemctl start vmtoolsd.service . |
Commande à lancer sous Ubuntu :
1 2 3 4 5 |
. sudo systemctl start open-vm-tools.service . |
liens :
- https://www.null-byte.org/vmware/rhel-centos-7-x-vmware-tools/
- https://kb.vmware.com/s/article/2073803
Redémarrer les VMware-Tools sous linux
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
. [root@monserveur vmware-tools]# ./services.sh status vmtoolsd is not running root@monserveur vmware-tools]# ./services.sh start Checking acpi hot plug [ OK ] Starting VMware Tools services in the virtual machine: Switching to guest configuration: [ OK ] VM communication interface: [ OK ] VM communication interface socket family: [ OK ] Guest operating system daemon: [ OK ] VGAuthService: [ OK ] [root@monserveur vmware-tools]# ./services.sh status vmtoolsd is running . |
Comment lister les Vms et leurs Adresses Mac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
. PS D:\> get-view -ViewType VirtualMachine | select NAME , @{N='Mac Address';E={[string]::Join(" , ",$($_.Guest.Net.MacAddress))}} Name Mac Address ---- ----------- mavm1 00:50:56:95:d1:e3 mavm2 00:50:56:56:05:9b mavm3 00:50:56:56:15:15 , 00:50:56:56:1e:1e , 00:50:56:56:1e:1e , 00:50:56:56:5a:1a mavm4 00:50:56:56:6d:70 mavm5 00:50:56:56:14:09 mavm6 76:31:9a:76:31:9a , 00:50:56:56:35:35 , 02:42:fb:02:42:fb mavm7 00:50:56:95:d6:ef . |
Comment retrouver une vm à partir de son Adresse Mac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
. $adressMac="00:50:56:56:5a:1a" PS D:\> get-view -ViewType VirtualMachine | Where-Object{$_.Guest.Net.MacAddress -eq $adressMac} | select NAME , @{N='Mac Address';E={[string]::Join(" , ",$($_.Guest.Net.MacAddress))}} Name Mac Address ---- ----------- mavm3 00:50:56:56:15:15 , 00:50:56:56:1e:1e , 00:50:56:56:1e:1e , 00:50:56:56:5a:1a . |