Author Archives: Munkhtuvshin Baatar

How to check that ntp server is configured properly for all esxi

#To get time and ntp info for  all esxi :

Get-VMHost | Sort Name | Select Name,  @{N="NTPServer";E={$_ |Get-VMHostNtpServer}},   Timezone,  @{N="CurrentTime";E={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}},  @{N="ServiceRunning";E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq "ntpd"}).Running}} ` | Format-Table -AutoSize

or 

Get-VMHost | Get-VMHostService | Where-Object {$_.key -eq "ntpd"} | select vmhost, label, Key, Policy, Running, Required |format-table -autosize

# Remove wrong NTP Server and Add correct NTP server

Get-VMHost | Remove-VMHostNtpServer -NtpServer ntp.mn Confirm:$false
Get-VMHost | Add-VMHostNtpServer -NtpServer 0.asia.pool.ntp.org

# Start NTP Service and set to Automatic

Get-VMHost | Get-VMHostService | Where-Object {$_.key -eq "ntpd" } | Start-VMHostService
Get-VMHost | Get-VMHostService | Where-Object {$_.key 
Read the rest

How to get detailed info about all VMs

Get-VMHost | Get-VM | Select-Object  Name, PowerState, NumCpu, MemoryMB, VMhost, @{N="Datastore";E={Get-Datastore -vm $_}}, UsedSpaceGB, ProvisionedSpaceGB, @{Name='ToolsVersion';Expression={$_.Guest.ToolsVersion}}, @{Name=’VMHostVersion’;Expression={$_.VMHost.Version}},Version, @{N="IP Address";E={@($_.guest.IPAddress[0])}}  |  Export-Csv -notypeinformation -path c:\temp\vms.csv

Read the rest

How to get CDP information for all esxi network adapters

It could be very handy to know to what switch, what switch port your esxi network adapters are connected.

get-vmhost | Get-VMHostNetworkAdapterCDP | Select-Object VMHost, NIC, Switch, PortID, connected, ManagementAddress,HardwarePlatform | Export-Csv -notypeinformation -Path c:\temp\cdp.csv

There is no standard method in PowerCLI with name “Get-VMHostNetworkAdapterCDP”.
To make it available you need in Powershell ISE
1. import all powerCLI modules (into command line at bottom of ISE) and press enter
2. copy paste below mentioned function to top windows of ISE and run it
3. enter finally above oneliner into bottom command line prompt

 

function Get-VMHostNetworkAdapterCDP {
<# .SYNOPSIS Function 
Read the rest

How to import powerCLI modules into standard Powershell ISE

Sometimes it’s useful to have opportunity to run and debug powerCLI scripts/functions from standard Powershell ISE

  1. install on AdminPC powerCLI
  2. open Powershell ISE
  3. copy and paste into command line below:
    Import-Module VMware.DeployAutomation
    Import-Module VMware.ImageBuilder
    Import-Module VMware.VimAutomation.Cis.Core
    Import-Module VMware.VimAutomation.Common
    Import-Module VMware.VimAutomation.Core
    Import-Module VMware.VimAutomation.HA
    Import-Module VMware.VimAutomation.License
    Import-Module VMware.VimAutomation.Sdk
    Import-Module VMware.VimAutomation.Storage
    Import-Module VMware.VimAutomation.vds
    
    
Read the rest

How to know what VMs have snapshot.

If you use Veeam Backup and Replication or Veritas Netbackup non-authorized snapshot can prevent backup/replica tasks (long term snapshots as backups is one of the most common mistakes, as cause of poor performance and as Vmware datastore low free space reason and so on ). So it’s important to know quickly what VMs have snapshot and delete/merge them.

Set-ExecutionPolicy RemoteSigned
connect-viserver vcenter.org.local
get-vm | get-snapshot | fl Description, Created, VM

if you want to delete/merge existing snapshots for all VMs:

Get-VM | Get-Snapshot | Remove-Snapshot -confirm:$false
Read the rest

SNMP and PRTG

The common mistake is to configure snmpd for v3 and forget to disable snmp v1/v2.

go to /etc/snmp/snmpd.conf and comment line with

“com2sec notConfigUser  default       public”

So full net-snmp installation and configuration should be something like:

  1. yum install -y net-snmp-utils net-snmp net-snmp-libs
  2. service snmpd status
  3. service snmpd stop
  4. net-snmp-create-v3-user -ro -A [password] -a MD5 -X snmpv3encPass -x DES snmpv3user
  5. comment line with “com2sec notConfigUser  default       public”
  6. service snmpd start
  7. configure PRTG or other monitoring tool
  8. chkconfig snmpd on
  9. snmptable -v 3 -u snmpv3user -l auth  -a MD5 -A [password] localhost usmUsertable
  10. snmpwalk -u snmpv3user -A [password] -a MD5 -l authnoPriv
Read the rest

Windows useful commands to troubleshoot time issues

  • w32tm /query /status (see source and ReferenceId, in AD output should NOT be “Source: Local CMOS Clock” or “VM IC Time Synchronization Provider”, nor “Free-running System Clock” – maybe need to run below two commands)
  • net time /set
  • net stop/start w32time
  • to compare time on DCs for small companies with only several AD DCs – for example from powershell: “net time \\dc00″,”net time \\dc01″,”net time \\dc02″,”net time \\dc03″,”net time \\dc04” | ForEach-Object {cmd.exe /c $_}
  • for PDC emulator role:       
  • w32tm /config /manualpeerlist:pool.ntp.org /syncfromflags:manual /reliable:yes /update
  • to reset computer time settings in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters:
  • net stop w32time
Read the rest